#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,lef,rig,mid,tes,t,n,m,i,j,p[500009],pi,pr[500009],ans[500009],pas,zx,xc,it;
int bo[500009],fls;
deque <int> de;
void dfs(int q){
bo[q]=i;
pi++;
p[pi]=q;
if(q+n<=mid){
it=q+n;
if(bo[it]==i){
fls=1;return;
}
if(bo[it]==-1) dfs(it);
if(fls==1) return;
}
if(q>=m){
it=q-m;
if(bo[it]==i){
fls=1;return;
}
if(bo[it]==-1) dfs(it);
if(fls==1) return;
}
}
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>tes;
// scanf("%d\n",&tes);
for(t=1; t<=tes; t++){
cin>>n>>m;
// scanf("%d %d\n",&n,&m);
lef=0;rig=400001;
pas=0;
// long long lonn=n,lonm=m;
// long long lon=lonn*lonm/__gcd(lonn,lonm),lonrg=rig;
// if(lonrg>lon) rig=lon;
/* if(rig==1){
// printf("0\n");
cout<<0<<endl;
continue;
}*/
// return 0;
while(1){
if(lef+1>=rig) break;
mid=(lef+rig)/2;
de.clear();
for(i=0; i<=mid; i++){
pr[i]=0;bo[i]=-1;
}
fls=0;
for(i=0; i<=mid; i++){
if(bo[i]==-1){
pi=0;
dfs(i);
if(fls==1) break;
for(j=pi; j>=1; j--){
de.push_front(p[j]);
}
}
}
if(fls==1){
rig=mid;
continue;
}
de.push_front(-1);
for(i=1; i<de.size(); i++){
if(de[i]==0){
zx=i;break;
}
}
for(i=1; i<de.size(); i++){
pr[de[i]]=zx-i;
}
pas=mid;
for(i=1; i<=mid; i++){
ans[i]=pr[i]-pr[i-1];
}
lef=mid;
}
// printf("%d\n",pas);
cout<<pas<<endl;
for(i=1; i<pas; i++) /*printf("%d ",ans[i]);*/cout<<ans[i]<<" ";
if(pas!=0){
// printf("%d\n",ans[pas]);
cout<<ans[pas]<<endl;
}
}
return 0;
}
Compilation message
sequence.cpp: In function 'int main()':
sequence.cpp:68:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=1; i<de.size(); i++){
~^~~~~~~~~~
sequence.cpp:73:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=1; i<de.size(); i++){
~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
5880 KB |
Ok |
2 |
Correct |
25 ms |
5880 KB |
Ok |
3 |
Correct |
10 ms |
2300 KB |
Ok |
4 |
Correct |
10 ms |
2168 KB |
Ok |
5 |
Correct |
10 ms |
2168 KB |
Ok |
6 |
Correct |
11 ms |
2936 KB |
Ok |
7 |
Correct |
10 ms |
2040 KB |
Ok |
8 |
Correct |
12 ms |
2936 KB |
Ok |
9 |
Correct |
9 ms |
2028 KB |
Ok |
10 |
Correct |
13 ms |
3836 KB |
Ok |
11 |
Correct |
10 ms |
2168 KB |
Ok |
12 |
Correct |
11 ms |
2040 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
3832 KB |
Ok |
2 |
Correct |
18 ms |
3960 KB |
Ok |
3 |
Correct |
23 ms |
3832 KB |
Ok |
4 |
Correct |
19 ms |
3960 KB |
Ok |
5 |
Correct |
19 ms |
3832 KB |
Ok |
6 |
Correct |
22 ms |
3960 KB |
Ok |
7 |
Correct |
47 ms |
4472 KB |
Ok |
8 |
Correct |
33 ms |
4088 KB |
Ok |
9 |
Correct |
47 ms |
4632 KB |
Ok |
10 |
Correct |
36 ms |
4344 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
5880 KB |
Ok |
2 |
Correct |
34 ms |
5860 KB |
Ok |
3 |
Correct |
23 ms |
3832 KB |
Ok |
4 |
Correct |
19 ms |
3320 KB |
Ok |
5 |
Correct |
22 ms |
5884 KB |
Ok |
6 |
Correct |
19 ms |
5880 KB |
Ok |
7 |
Correct |
23 ms |
5756 KB |
Ok |
8 |
Correct |
19 ms |
5880 KB |
Ok |
9 |
Correct |
19 ms |
5880 KB |
Ok |
10 |
Correct |
17 ms |
3960 KB |
Ok |
11 |
Correct |
14 ms |
3208 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
3832 KB |
Ok |
2 |
Correct |
12 ms |
2552 KB |
Ok |
3 |
Correct |
11 ms |
2168 KB |
Ok |
4 |
Correct |
11 ms |
2168 KB |
Ok |
5 |
Correct |
10 ms |
2048 KB |
Ok |
6 |
Correct |
275 ms |
8544 KB |
Ok |
7 |
Correct |
250 ms |
8092 KB |
Ok |
8 |
Correct |
471 ms |
11144 KB |
Ok |
9 |
Correct |
348 ms |
10060 KB |
Ok |
10 |
Correct |
203 ms |
5496 KB |
Ok |
11 |
Correct |
365 ms |
9656 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
5880 KB |
Ok |
2 |
Correct |
25 ms |
5880 KB |
Ok |
3 |
Correct |
10 ms |
2300 KB |
Ok |
4 |
Correct |
10 ms |
2168 KB |
Ok |
5 |
Correct |
10 ms |
2168 KB |
Ok |
6 |
Correct |
11 ms |
2936 KB |
Ok |
7 |
Correct |
10 ms |
2040 KB |
Ok |
8 |
Correct |
12 ms |
2936 KB |
Ok |
9 |
Correct |
9 ms |
2028 KB |
Ok |
10 |
Correct |
13 ms |
3836 KB |
Ok |
11 |
Correct |
10 ms |
2168 KB |
Ok |
12 |
Correct |
11 ms |
2040 KB |
Ok |
13 |
Correct |
14 ms |
5880 KB |
Ok |
14 |
Correct |
34 ms |
5860 KB |
Ok |
15 |
Correct |
23 ms |
3832 KB |
Ok |
16 |
Correct |
19 ms |
3320 KB |
Ok |
17 |
Correct |
22 ms |
5884 KB |
Ok |
18 |
Correct |
19 ms |
5880 KB |
Ok |
19 |
Correct |
23 ms |
5756 KB |
Ok |
20 |
Correct |
19 ms |
5880 KB |
Ok |
21 |
Correct |
19 ms |
5880 KB |
Ok |
22 |
Correct |
17 ms |
3960 KB |
Ok |
23 |
Correct |
14 ms |
3208 KB |
Ok |
24 |
Correct |
12 ms |
2040 KB |
Ok |
25 |
Correct |
12 ms |
2040 KB |
Ok |
26 |
Correct |
14 ms |
2040 KB |
Ok |
27 |
Correct |
12 ms |
2040 KB |
Ok |
28 |
Correct |
12 ms |
2040 KB |
Ok |
29 |
Correct |
12 ms |
2040 KB |
Ok |
30 |
Correct |
12 ms |
1912 KB |
Ok |
31 |
Correct |
13 ms |
2040 KB |
Ok |
32 |
Correct |
12 ms |
2040 KB |
Ok |
33 |
Correct |
13 ms |
2040 KB |
Ok |
34 |
Correct |
18 ms |
2168 KB |
Ok |
35 |
Correct |
19 ms |
2168 KB |
Ok |
36 |
Correct |
18 ms |
2296 KB |
Ok |
37 |
Correct |
19 ms |
2168 KB |
Ok |
38 |
Correct |
18 ms |
2168 KB |
Ok |
39 |
Correct |
18 ms |
2168 KB |
Ok |
40 |
Correct |
21 ms |
2168 KB |
Ok |
41 |
Correct |
19 ms |
2172 KB |
Ok |
42 |
Correct |
19 ms |
2168 KB |
Ok |
43 |
Correct |
21 ms |
2168 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
5880 KB |
Ok |
2 |
Correct |
25 ms |
5880 KB |
Ok |
3 |
Correct |
10 ms |
2300 KB |
Ok |
4 |
Correct |
10 ms |
2168 KB |
Ok |
5 |
Correct |
10 ms |
2168 KB |
Ok |
6 |
Correct |
11 ms |
2936 KB |
Ok |
7 |
Correct |
10 ms |
2040 KB |
Ok |
8 |
Correct |
12 ms |
2936 KB |
Ok |
9 |
Correct |
9 ms |
2028 KB |
Ok |
10 |
Correct |
13 ms |
3836 KB |
Ok |
11 |
Correct |
10 ms |
2168 KB |
Ok |
12 |
Correct |
11 ms |
2040 KB |
Ok |
13 |
Correct |
24 ms |
3832 KB |
Ok |
14 |
Correct |
18 ms |
3960 KB |
Ok |
15 |
Correct |
23 ms |
3832 KB |
Ok |
16 |
Correct |
19 ms |
3960 KB |
Ok |
17 |
Correct |
19 ms |
3832 KB |
Ok |
18 |
Correct |
22 ms |
3960 KB |
Ok |
19 |
Correct |
47 ms |
4472 KB |
Ok |
20 |
Correct |
33 ms |
4088 KB |
Ok |
21 |
Correct |
47 ms |
4632 KB |
Ok |
22 |
Correct |
36 ms |
4344 KB |
Ok |
23 |
Correct |
14 ms |
5880 KB |
Ok |
24 |
Correct |
34 ms |
5860 KB |
Ok |
25 |
Correct |
23 ms |
3832 KB |
Ok |
26 |
Correct |
19 ms |
3320 KB |
Ok |
27 |
Correct |
22 ms |
5884 KB |
Ok |
28 |
Correct |
19 ms |
5880 KB |
Ok |
29 |
Correct |
23 ms |
5756 KB |
Ok |
30 |
Correct |
19 ms |
5880 KB |
Ok |
31 |
Correct |
19 ms |
5880 KB |
Ok |
32 |
Correct |
17 ms |
3960 KB |
Ok |
33 |
Correct |
14 ms |
3208 KB |
Ok |
34 |
Correct |
12 ms |
2040 KB |
Ok |
35 |
Correct |
12 ms |
2040 KB |
Ok |
36 |
Correct |
14 ms |
2040 KB |
Ok |
37 |
Correct |
12 ms |
2040 KB |
Ok |
38 |
Correct |
12 ms |
2040 KB |
Ok |
39 |
Correct |
12 ms |
2040 KB |
Ok |
40 |
Correct |
12 ms |
1912 KB |
Ok |
41 |
Correct |
13 ms |
2040 KB |
Ok |
42 |
Correct |
12 ms |
2040 KB |
Ok |
43 |
Correct |
13 ms |
2040 KB |
Ok |
44 |
Correct |
18 ms |
2168 KB |
Ok |
45 |
Correct |
19 ms |
2168 KB |
Ok |
46 |
Correct |
18 ms |
2296 KB |
Ok |
47 |
Correct |
19 ms |
2168 KB |
Ok |
48 |
Correct |
18 ms |
2168 KB |
Ok |
49 |
Correct |
18 ms |
2168 KB |
Ok |
50 |
Correct |
21 ms |
2168 KB |
Ok |
51 |
Correct |
19 ms |
2172 KB |
Ok |
52 |
Correct |
19 ms |
2168 KB |
Ok |
53 |
Correct |
21 ms |
2168 KB |
Ok |
54 |
Correct |
185 ms |
4380 KB |
Ok |
55 |
Correct |
235 ms |
4728 KB |
Ok |
56 |
Correct |
224 ms |
4768 KB |
Ok |
57 |
Correct |
165 ms |
3960 KB |
Ok |
58 |
Correct |
198 ms |
4196 KB |
Ok |
59 |
Correct |
195 ms |
4152 KB |
Ok |
60 |
Correct |
161 ms |
3924 KB |
Ok |
61 |
Correct |
158 ms |
3912 KB |
Ok |
62 |
Correct |
226 ms |
4472 KB |
Ok |
63 |
Correct |
170 ms |
4236 KB |
Ok |
64 |
Correct |
214 ms |
4692 KB |
Ok |
65 |
Correct |
220 ms |
4348 KB |
Ok |
66 |
Correct |
184 ms |
4216 KB |
Ok |
67 |
Correct |
171 ms |
4212 KB |
Ok |
68 |
Correct |
190 ms |
4216 KB |
Ok |
69 |
Correct |
477 ms |
9932 KB |
Ok |
70 |
Correct |
473 ms |
10488 KB |
Ok |
71 |
Correct |
432 ms |
9980 KB |
Ok |
72 |
Correct |
446 ms |
10012 KB |
Ok |
73 |
Correct |
430 ms |
9976 KB |
Ok |
74 |
Correct |
425 ms |
9980 KB |
Ok |
75 |
Correct |
447 ms |
9488 KB |
Ok |
76 |
Correct |
501 ms |
10240 KB |
Ok |
77 |
Correct |
396 ms |
9444 KB |
Ok |
78 |
Correct |
458 ms |
9976 KB |
Ok |
79 |
Correct |
426 ms |
10104 KB |
Ok |
80 |
Correct |
447 ms |
10340 KB |
Ok |
81 |
Correct |
478 ms |
10008 KB |
Ok |
82 |
Correct |
441 ms |
10144 KB |
Ok |
83 |
Correct |
431 ms |
9720 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
5880 KB |
Ok |
2 |
Correct |
25 ms |
5880 KB |
Ok |
3 |
Correct |
10 ms |
2300 KB |
Ok |
4 |
Correct |
10 ms |
2168 KB |
Ok |
5 |
Correct |
10 ms |
2168 KB |
Ok |
6 |
Correct |
11 ms |
2936 KB |
Ok |
7 |
Correct |
10 ms |
2040 KB |
Ok |
8 |
Correct |
12 ms |
2936 KB |
Ok |
9 |
Correct |
9 ms |
2028 KB |
Ok |
10 |
Correct |
13 ms |
3836 KB |
Ok |
11 |
Correct |
10 ms |
2168 KB |
Ok |
12 |
Correct |
11 ms |
2040 KB |
Ok |
13 |
Correct |
24 ms |
3832 KB |
Ok |
14 |
Correct |
18 ms |
3960 KB |
Ok |
15 |
Correct |
23 ms |
3832 KB |
Ok |
16 |
Correct |
19 ms |
3960 KB |
Ok |
17 |
Correct |
19 ms |
3832 KB |
Ok |
18 |
Correct |
22 ms |
3960 KB |
Ok |
19 |
Correct |
47 ms |
4472 KB |
Ok |
20 |
Correct |
33 ms |
4088 KB |
Ok |
21 |
Correct |
47 ms |
4632 KB |
Ok |
22 |
Correct |
36 ms |
4344 KB |
Ok |
23 |
Correct |
14 ms |
5880 KB |
Ok |
24 |
Correct |
34 ms |
5860 KB |
Ok |
25 |
Correct |
23 ms |
3832 KB |
Ok |
26 |
Correct |
19 ms |
3320 KB |
Ok |
27 |
Correct |
22 ms |
5884 KB |
Ok |
28 |
Correct |
19 ms |
5880 KB |
Ok |
29 |
Correct |
23 ms |
5756 KB |
Ok |
30 |
Correct |
19 ms |
5880 KB |
Ok |
31 |
Correct |
19 ms |
5880 KB |
Ok |
32 |
Correct |
17 ms |
3960 KB |
Ok |
33 |
Correct |
14 ms |
3208 KB |
Ok |
34 |
Correct |
19 ms |
3832 KB |
Ok |
35 |
Correct |
12 ms |
2552 KB |
Ok |
36 |
Correct |
11 ms |
2168 KB |
Ok |
37 |
Correct |
11 ms |
2168 KB |
Ok |
38 |
Correct |
10 ms |
2048 KB |
Ok |
39 |
Correct |
275 ms |
8544 KB |
Ok |
40 |
Correct |
250 ms |
8092 KB |
Ok |
41 |
Correct |
471 ms |
11144 KB |
Ok |
42 |
Correct |
348 ms |
10060 KB |
Ok |
43 |
Correct |
203 ms |
5496 KB |
Ok |
44 |
Correct |
365 ms |
9656 KB |
Ok |
45 |
Correct |
12 ms |
2040 KB |
Ok |
46 |
Correct |
12 ms |
2040 KB |
Ok |
47 |
Correct |
14 ms |
2040 KB |
Ok |
48 |
Correct |
12 ms |
2040 KB |
Ok |
49 |
Correct |
12 ms |
2040 KB |
Ok |
50 |
Correct |
12 ms |
2040 KB |
Ok |
51 |
Correct |
12 ms |
1912 KB |
Ok |
52 |
Correct |
13 ms |
2040 KB |
Ok |
53 |
Correct |
12 ms |
2040 KB |
Ok |
54 |
Correct |
13 ms |
2040 KB |
Ok |
55 |
Correct |
18 ms |
2168 KB |
Ok |
56 |
Correct |
19 ms |
2168 KB |
Ok |
57 |
Correct |
18 ms |
2296 KB |
Ok |
58 |
Correct |
19 ms |
2168 KB |
Ok |
59 |
Correct |
18 ms |
2168 KB |
Ok |
60 |
Correct |
18 ms |
2168 KB |
Ok |
61 |
Correct |
21 ms |
2168 KB |
Ok |
62 |
Correct |
19 ms |
2172 KB |
Ok |
63 |
Correct |
19 ms |
2168 KB |
Ok |
64 |
Correct |
21 ms |
2168 KB |
Ok |
65 |
Correct |
185 ms |
4380 KB |
Ok |
66 |
Correct |
235 ms |
4728 KB |
Ok |
67 |
Correct |
224 ms |
4768 KB |
Ok |
68 |
Correct |
165 ms |
3960 KB |
Ok |
69 |
Correct |
198 ms |
4196 KB |
Ok |
70 |
Correct |
195 ms |
4152 KB |
Ok |
71 |
Correct |
161 ms |
3924 KB |
Ok |
72 |
Correct |
158 ms |
3912 KB |
Ok |
73 |
Correct |
226 ms |
4472 KB |
Ok |
74 |
Correct |
170 ms |
4236 KB |
Ok |
75 |
Correct |
214 ms |
4692 KB |
Ok |
76 |
Correct |
220 ms |
4348 KB |
Ok |
77 |
Correct |
184 ms |
4216 KB |
Ok |
78 |
Correct |
171 ms |
4212 KB |
Ok |
79 |
Correct |
190 ms |
4216 KB |
Ok |
80 |
Correct |
477 ms |
9932 KB |
Ok |
81 |
Correct |
473 ms |
10488 KB |
Ok |
82 |
Correct |
432 ms |
9980 KB |
Ok |
83 |
Correct |
446 ms |
10012 KB |
Ok |
84 |
Correct |
430 ms |
9976 KB |
Ok |
85 |
Correct |
425 ms |
9980 KB |
Ok |
86 |
Correct |
447 ms |
9488 KB |
Ok |
87 |
Correct |
501 ms |
10240 KB |
Ok |
88 |
Correct |
396 ms |
9444 KB |
Ok |
89 |
Correct |
458 ms |
9976 KB |
Ok |
90 |
Correct |
426 ms |
10104 KB |
Ok |
91 |
Correct |
447 ms |
10340 KB |
Ok |
92 |
Correct |
478 ms |
10008 KB |
Ok |
93 |
Correct |
441 ms |
10144 KB |
Ok |
94 |
Correct |
431 ms |
9720 KB |
Ok |
95 |
Correct |
498 ms |
9008 KB |
Ok |
96 |
Correct |
724 ms |
12140 KB |
Ok |
97 |
Correct |
702 ms |
10032 KB |
Ok |
98 |
Correct |
524 ms |
9272 KB |
Ok |
99 |
Correct |
672 ms |
9496 KB |
Ok |
100 |
Correct |
616 ms |
9632 KB |
Ok |
101 |
Correct |
729 ms |
10996 KB |
Ok |
102 |
Correct |
659 ms |
10096 KB |
Ok |
103 |
Correct |
638 ms |
10260 KB |
Ok |
104 |
Correct |
795 ms |
11996 KB |
Ok |
105 |
Correct |
656 ms |
11792 KB |
Ok |
106 |
Correct |
631 ms |
11464 KB |
Ok |
107 |
Correct |
740 ms |
11248 KB |
Ok |
108 |
Correct |
725 ms |
12040 KB |
Ok |
109 |
Correct |
671 ms |
12024 KB |
Ok |
110 |
Execution timed out |
2058 ms |
34192 KB |
Time limit exceeded |
111 |
Halted |
0 ms |
0 KB |
- |