QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#591611#9310. Permutation Counting 4TytytonyTL 2748ms5816kbC++231.4kb2024-09-26 16:45:062024-09-26 16:45:06

Judging History

你现在查看的是最新测评结果

  • [2024-09-26 16:45:06]
  • 评测
  • 测评结果:TL
  • 用时:2748ms
  • 内存:5816kb
  • [2024-09-26 16:45:06]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define N 1000010
using namespace std;

int n,flag=0;
int l[N],r[N];

void clean(){
	flag=0;
	memset(l,0,(n+10)*sizeof(int));
	memset(r,0,(n+10)*sizeof(int));
	for(int i=1;i<=n;i++){
		l[i]=0;
		r[i]=0;
	}
}

// 快读 
int read(){
	int x = 0, f = 1;
	char c = getchar();
	while(c < '0' || c > '9'){
		if(c == '-'){
			f = -1;
		}
		c = getchar();
	}
	while(c >= '0' && c <= '9'){
		x = x*10+c-'0';
		c = getchar();
	}
	return x*f;
}

void pc(int ll,int rr){
	if(flag==1) return;
	if(l[ll]!=0){
		if(l[ll]==rr){
			flag=1;
			return;
		}
		while(l[ll]!=0&&l[ll]<rr){
			ll=l[ll]+1;
		}
		if(l[ll]>rr){
			int tmpl=rr+1,tmpr=l[ll];
			r[l[ll]]=0;
			l[ll]=0;
			pc(tmpl,tmpr);
		}
		
	}
	if(flag==1) return;
	if(r[rr]!=0){
		if(r[rr]==ll){
			flag=1;
			return;
		}
		while(r[rr]!=0&&r[rr]>ll){
			rr=r[rr]-1;
		}
		if(r[rr]<ll){
			int tmpl=r[rr],tmpr=ll-1;
			l[r[rr]]=0;
			r[rr]=0;
			pc(tmpl,tmpr);
		}
		
	}
	if(flag==1) return;
	l[ll]=rr;
	r[rr]=ll;
	return;
}

int main(){
	int T; cin>>T;
	while(T--){
		cin>>n;
		clean();
		for(int i=0;i<n;i++){
			int tmpl,tmpr;
			tmpl=read(),tmpr=read();
			if(flag==0) pc(tmpl,tmpr);
		}
		if(flag==0) cout<<1<<endl;
		else cout<<0<<endl;
	} 
	return 0;

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5732kb

input:

4
5
1 2
1 5
1 2
1 2
2 2
5
1 1
2 4
2 3
5 5
3 4
5
3 5
1 2
3 4
3 5
3 3
5
1 5
1 4
4 5
5 5
1 2

output:

0
1
0
0

result:

ok 4 tokens

Test #2:

score: 0
Accepted
time: 56ms
memory: 5756kb

input:

66725
14
7 7
4 6
7 8
8 13
2 13
6 13
6 10
14 14
1 10
9 11
7 9
3 8
4 12
5 12
12
2 6
3 6
7 11
2 5
1 1
6 12
8 12
2 3
7 9
7 8
1 10
1 4
10
4 8
4 4
6 10
9 10
2 3
2 7
1 3
3 4
2 2
3 10
20
3 12
10 14
19 20
19 20
1 9
7 9
13 16
17 17
16 18
2 11
5 19
6 17
11 17
3 6
3 11
7 20
8 17
3 18
10 15
9 20
16
5 10
2 10
2 1...

output:

1
1
0
0
1
0
1
1
0
1
1
0
0
0
0
0
1
0
1
0
0
1
0
0
0
1
0
1
0
0
0
0
1
0
1
1
1
1
1
0
1
0
1
1
1
1
1
1
1
1
0
1
1
0
0
0
0
0
0
1
0
1
1
0
1
1
1
0
1
0
1
0
0
0
1
1
1
0
0
1
1
1
1
0
1
1
1
1
1
1
1
0
1
0
0
1
1
0
0
1
1
0
0
1
1
1
1
1
1
0
0
1
1
1
0
0
1
1
0
0
1
0
1
0
1
0
1
0
0
0
0
0
0
0
0
1
1
1
1
1
0
0
0
1
0
0
1
0
1
1
...

result:

ok 66725 tokens

Test #3:

score: 0
Accepted
time: 76ms
memory: 5816kb

input:

6655
155
28 58
68 100
6 47
98 109
11 133
38 153
73 118
126 153
24 43
71 118
109 135
6 104
40 101
24 139
100 136
135 136
40 148
70 117
92 124
63 64
45 55
16 128
65 86
20 49
126 138
30 141
127 146
21 155
49 139
27 34
39 145
20 53
12 41
3 107
38 78
106 109
61 102
20 99
134 135
23 99
10 69
105 113
36 75...

output:

0
0
1
1
0
1
0
0
1
1
0
1
1
1
0
0
1
1
1
0
1
0
1
0
1
0
0
1
1
0
1
0
0
0
1
1
0
1
0
1
0
1
0
1
1
1
1
0
1
0
0
0
0
0
1
1
0
1
0
1
0
1
0
1
0
0
1
0
0
1
0
0
0
1
0
1
1
0
1
0
0
0
0
0
0
1
0
1
0
0
1
0
0
1
0
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
1
1
0
0
0
0
0
1
0
1
0
1
0
0
0
0
1
0
1
0
0
1
0
1
0
0
1
0
1
0
0
1
1
1
0
0
0
0
...

result:

ok 6655 tokens

Test #4:

score: 0
Accepted
time: 309ms
memory: 5764kb

input:

666
1967
396 1664
818 1954
564 805
1106 1322
568 1687
853 1482
153 1092
566 670
154 562
114 1372
574 1879
482 1083
499 1566
2 1384
291 1947
122 1714
1277 1900
740 1024
887 1478
146 254
944 1807
574 1193
225 1933
43 1278
1017 1482
958 1180
86 1230
1658 1679
980 1542
1044 1127
762 989
1128 1567
552 17...

output:

0
0
0
0
1
1
1
0
0
0
0
0
0
1
1
0
0
0
1
0
0
0
0
1
1
1
0
0
0
0
1
1
0
0
1
0
1
0
1
0
0
1
0
0
1
0
0
0
0
0
1
1
0
1
1
1
1
0
1
1
1
1
1
0
1
0
0
0
0
1
1
0
0
1
0
1
1
0
1
0
0
1
1
1
1
1
0
1
1
1
0
0
1
0
0
0
0
0
1
0
0
0
0
1
1
0
1
1
1
1
1
0
1
1
0
1
0
0
1
1
1
1
1
0
0
1
1
0
0
1
0
0
1
0
1
1
0
1
1
1
1
1
1
0
0
0
0
1
1
0
...

result:

ok 666 tokens

Test #5:

score: 0
Accepted
time: 2748ms
memory: 5772kb

input:

67
12220
945 3456
3457 11698
945 3023
945 10249
945 6035
3457 12211
3024 9082
6554 10249
3179 11698
945 2449
3457 6897
945 3625
4115 9082
3626 11593
2450 3525
3526 5410
3179 5606
5607 8510
5607 8159
1908 9082
6898 9270
3457 4922
6669 9082
2936 10249
2936 9009
1796 5410
4923 10474
2450 5488
3526 6232...

output:

1
1
0
1
1
1
0
0
0
1
0
0
0
0
1
1
1
1
1
0
0
0
0
1
1
0
0
1
0
0
1
0
1
1
0
1
1
0
0
1
1
0
1
1
0
0
0
0
1
0
1
1
0
1
1
1
0
1
1
0
0
1
1
1
1
0
1

result:

ok 67 tokens

Test #6:

score: -100
Time Limit Exceeded

input:

6
189286
20378 70057
112636 186453
18829 100288
79275 115176
63489 100397
91394 117835
82935 156201
139293 142914
73817 98058
45394 109570
29456 122157
137106 187436
155188 173045
78214 89538
128432 165866
151755 155927
10312 86728
127548 136028
27985 151840
67594 139392
116691 134229
83762 102392
2...

output:

0
0

result: