QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#831#571761#9310. Permutation Counting 4N_z_ship2077Success!2024-09-18 14:40:322024-09-18 14:40:33

Details

Extra Test:

Time Limit Exceeded

input:

1
1000000
1 1
1 2
2 3
1 4
2 5
3 6
4 7
1 8
2 9
3 10
4 11
5 12
6 13
7 14
8 15
1 16
2 17
3 18
4 19
5 20
6 21
7 22
8 23
9 24
10 25
11 26
12 27
13 28
14 29
15 30
16 31
1 32
2 33
3 34
4 35
5 36
6 37
7 38
8 39
9 40
10 41
11 42
12 43
13 44
14 45
15 46
16 47
17 48
18 49
19 50
20 51
21 52
22 53
23 54
24 55
25...

output:

1

result:


IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#571761#9310. Permutation Counting 4ship2077#TL 842ms194040kbC++23573b2024-09-18 08:15:042024-10-14 07:43:44

answer

#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
constexpr int M=1e6+5;
set<int>s[M];int n;
void solve(){ cin>>n;
	for (int i=1;i<=n;i++) s[i].clear();
	for (int i=1;i<=n;i++){
		int l,r;cin>>l>>r;
		s[l].insert(r);
	}
	for (int i=1;i<=n;i++){
		if (s[i].empty()) return puts("0"),void();
		int lst=0;
		for (auto x:s[i]){
			if (lst) s[lst+1].insert(x);
			lst=x;
		}
	}
	puts("1");
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T;cin>>T;while (T--) solve();return 0;
}