#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 4e6+5;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val);}
int a[N], n, m, k;
bool used[N];
vector<int> order;
int md;
void dfs(int u){
used[u] = true;
if(u-n >= 0 && !used[u-n])dfs(u-n);
if(u+m <= md && !used[u+m])dfs(u+m);
order.pb(u);
}
bool check(int mid){
int i;
md = mid;
order.clear();
memset(used, 0, sizeof(used));
for(i=0;i<=mid;i++)if(!used[i])dfs(i);
for(i=0;i<=mid;i++)a[order[i]] = i;
for(i=0;i<=mid;i++){
if(i-n >= 0){
if(a[i]-a[i-n] <=0)return false;
}else if(i-m >= 0){
if(a[i]-a[i-m] >=0)return false;
}
}return true;
}
void solve(int test_case){
int i, j;
cin >> n >> m;
int l = 0, r = n+m+1;
check(l);
while(l+1 < r){
int mid = (l+r)/2;
// cout << l << ' ' << r << ' ' << mid << '\n';
if(check(mid))l = mid;
else r = mid;
}
cout << l << '\n';
assert(l != -1);
check(l);
for(i=1;i<=l;i++){
cout << -(a[i]-a[i-1]) << ' ';
}cout << '\n';
return;
}
signed main(){
FASTIO;
#define MULTITEST 1
#if MULTITEST
int ___T;
cin >> ___T;
for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
solve(T_CASE);
#else
solve(1);
#endif
return 0;
}
Compilation message
sequence.cpp: In function 'void solve(long long int)':
sequence.cpp:41:9: warning: unused variable 'j' [-Wunused-variable]
41 | int i, j;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
4204 KB |
Ok |
2 |
Correct |
15 ms |
4204 KB |
Ok |
3 |
Correct |
16 ms |
4224 KB |
Ok |
4 |
Correct |
16 ms |
4208 KB |
Ok |
5 |
Correct |
17 ms |
4204 KB |
Ok |
6 |
Correct |
16 ms |
4204 KB |
Ok |
7 |
Correct |
16 ms |
4224 KB |
Ok |
8 |
Correct |
16 ms |
4224 KB |
Ok |
9 |
Correct |
17 ms |
4332 KB |
Ok |
10 |
Correct |
16 ms |
4204 KB |
Ok |
11 |
Correct |
16 ms |
4204 KB |
Ok |
12 |
Correct |
17 ms |
4204 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
4204 KB |
Ok |
2 |
Correct |
12 ms |
4204 KB |
Ok |
3 |
Correct |
13 ms |
4204 KB |
Ok |
4 |
Correct |
13 ms |
4204 KB |
Ok |
5 |
Correct |
14 ms |
4332 KB |
Ok |
6 |
Correct |
26 ms |
4460 KB |
Ok |
7 |
Correct |
49 ms |
5228 KB |
Ok |
8 |
Correct |
33 ms |
4588 KB |
Ok |
9 |
Correct |
53 ms |
5356 KB |
Ok |
10 |
Correct |
47 ms |
4844 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4204 KB |
Ok |
2 |
Correct |
9 ms |
4204 KB |
Ok |
3 |
Correct |
10 ms |
4204 KB |
Ok |
4 |
Correct |
10 ms |
4204 KB |
Ok |
5 |
Correct |
11 ms |
4204 KB |
Ok |
6 |
Correct |
13 ms |
4332 KB |
Ok |
7 |
Correct |
11 ms |
4204 KB |
Ok |
8 |
Correct |
12 ms |
4204 KB |
Ok |
9 |
Correct |
13 ms |
4204 KB |
Ok |
10 |
Correct |
12 ms |
4204 KB |
Ok |
11 |
Correct |
11 ms |
4204 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
4204 KB |
Ok |
2 |
Correct |
12 ms |
4204 KB |
Ok |
3 |
Correct |
13 ms |
4204 KB |
Ok |
4 |
Correct |
14 ms |
4204 KB |
Ok |
5 |
Correct |
15 ms |
4204 KB |
Ok |
6 |
Correct |
348 ms |
15332 KB |
Ok |
7 |
Correct |
294 ms |
15844 KB |
Ok |
8 |
Correct |
541 ms |
18020 KB |
Ok |
9 |
Correct |
417 ms |
18020 KB |
Ok |
10 |
Correct |
292 ms |
11880 KB |
Ok |
11 |
Correct |
457 ms |
18532 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
4204 KB |
Ok |
2 |
Correct |
15 ms |
4204 KB |
Ok |
3 |
Correct |
16 ms |
4224 KB |
Ok |
4 |
Correct |
16 ms |
4208 KB |
Ok |
5 |
Correct |
17 ms |
4204 KB |
Ok |
6 |
Correct |
16 ms |
4204 KB |
Ok |
7 |
Correct |
16 ms |
4224 KB |
Ok |
8 |
Correct |
16 ms |
4224 KB |
Ok |
9 |
Correct |
17 ms |
4332 KB |
Ok |
10 |
Correct |
16 ms |
4204 KB |
Ok |
11 |
Correct |
16 ms |
4204 KB |
Ok |
12 |
Correct |
17 ms |
4204 KB |
Ok |
13 |
Correct |
5 ms |
4204 KB |
Ok |
14 |
Correct |
9 ms |
4204 KB |
Ok |
15 |
Correct |
10 ms |
4204 KB |
Ok |
16 |
Correct |
10 ms |
4204 KB |
Ok |
17 |
Correct |
11 ms |
4204 KB |
Ok |
18 |
Correct |
13 ms |
4332 KB |
Ok |
19 |
Correct |
11 ms |
4204 KB |
Ok |
20 |
Correct |
12 ms |
4204 KB |
Ok |
21 |
Correct |
13 ms |
4204 KB |
Ok |
22 |
Correct |
12 ms |
4204 KB |
Ok |
23 |
Correct |
11 ms |
4204 KB |
Ok |
24 |
Correct |
29 ms |
4332 KB |
Ok |
25 |
Correct |
27 ms |
4460 KB |
Ok |
26 |
Correct |
27 ms |
4332 KB |
Ok |
27 |
Correct |
29 ms |
4460 KB |
Ok |
28 |
Correct |
26 ms |
4332 KB |
Ok |
29 |
Correct |
27 ms |
4332 KB |
Ok |
30 |
Correct |
26 ms |
4332 KB |
Ok |
31 |
Correct |
27 ms |
4332 KB |
Ok |
32 |
Correct |
27 ms |
4332 KB |
Ok |
33 |
Correct |
27 ms |
4332 KB |
Ok |
34 |
Correct |
34 ms |
4588 KB |
Ok |
35 |
Correct |
34 ms |
4588 KB |
Ok |
36 |
Correct |
35 ms |
4588 KB |
Ok |
37 |
Correct |
33 ms |
4588 KB |
Ok |
38 |
Correct |
34 ms |
4588 KB |
Ok |
39 |
Correct |
33 ms |
4588 KB |
Ok |
40 |
Correct |
36 ms |
4844 KB |
Ok |
41 |
Correct |
32 ms |
4588 KB |
Ok |
42 |
Correct |
34 ms |
4608 KB |
Ok |
43 |
Correct |
34 ms |
4588 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
4204 KB |
Ok |
2 |
Correct |
15 ms |
4204 KB |
Ok |
3 |
Correct |
16 ms |
4224 KB |
Ok |
4 |
Correct |
16 ms |
4208 KB |
Ok |
5 |
Correct |
17 ms |
4204 KB |
Ok |
6 |
Correct |
16 ms |
4204 KB |
Ok |
7 |
Correct |
16 ms |
4224 KB |
Ok |
8 |
Correct |
16 ms |
4224 KB |
Ok |
9 |
Correct |
17 ms |
4332 KB |
Ok |
10 |
Correct |
16 ms |
4204 KB |
Ok |
11 |
Correct |
16 ms |
4204 KB |
Ok |
12 |
Correct |
17 ms |
4204 KB |
Ok |
13 |
Correct |
10 ms |
4204 KB |
Ok |
14 |
Correct |
12 ms |
4204 KB |
Ok |
15 |
Correct |
13 ms |
4204 KB |
Ok |
16 |
Correct |
13 ms |
4204 KB |
Ok |
17 |
Correct |
14 ms |
4332 KB |
Ok |
18 |
Correct |
26 ms |
4460 KB |
Ok |
19 |
Correct |
49 ms |
5228 KB |
Ok |
20 |
Correct |
33 ms |
4588 KB |
Ok |
21 |
Correct |
53 ms |
5356 KB |
Ok |
22 |
Correct |
47 ms |
4844 KB |
Ok |
23 |
Correct |
5 ms |
4204 KB |
Ok |
24 |
Correct |
9 ms |
4204 KB |
Ok |
25 |
Correct |
10 ms |
4204 KB |
Ok |
26 |
Correct |
10 ms |
4204 KB |
Ok |
27 |
Correct |
11 ms |
4204 KB |
Ok |
28 |
Correct |
13 ms |
4332 KB |
Ok |
29 |
Correct |
11 ms |
4204 KB |
Ok |
30 |
Correct |
12 ms |
4204 KB |
Ok |
31 |
Correct |
13 ms |
4204 KB |
Ok |
32 |
Correct |
12 ms |
4204 KB |
Ok |
33 |
Correct |
11 ms |
4204 KB |
Ok |
34 |
Correct |
29 ms |
4332 KB |
Ok |
35 |
Correct |
27 ms |
4460 KB |
Ok |
36 |
Correct |
27 ms |
4332 KB |
Ok |
37 |
Correct |
29 ms |
4460 KB |
Ok |
38 |
Correct |
26 ms |
4332 KB |
Ok |
39 |
Correct |
27 ms |
4332 KB |
Ok |
40 |
Correct |
26 ms |
4332 KB |
Ok |
41 |
Correct |
27 ms |
4332 KB |
Ok |
42 |
Correct |
27 ms |
4332 KB |
Ok |
43 |
Correct |
27 ms |
4332 KB |
Ok |
44 |
Correct |
34 ms |
4588 KB |
Ok |
45 |
Correct |
34 ms |
4588 KB |
Ok |
46 |
Correct |
35 ms |
4588 KB |
Ok |
47 |
Correct |
33 ms |
4588 KB |
Ok |
48 |
Correct |
34 ms |
4588 KB |
Ok |
49 |
Correct |
33 ms |
4588 KB |
Ok |
50 |
Correct |
36 ms |
4844 KB |
Ok |
51 |
Correct |
32 ms |
4588 KB |
Ok |
52 |
Correct |
34 ms |
4608 KB |
Ok |
53 |
Correct |
34 ms |
4588 KB |
Ok |
54 |
Correct |
248 ms |
8040 KB |
Ok |
55 |
Correct |
268 ms |
8424 KB |
Ok |
56 |
Correct |
266 ms |
8296 KB |
Ok |
57 |
Correct |
213 ms |
7656 KB |
Ok |
58 |
Correct |
257 ms |
8296 KB |
Ok |
59 |
Correct |
251 ms |
8168 KB |
Ok |
60 |
Correct |
217 ms |
7656 KB |
Ok |
61 |
Correct |
210 ms |
7784 KB |
Ok |
62 |
Correct |
286 ms |
8680 KB |
Ok |
63 |
Correct |
238 ms |
8040 KB |
Ok |
64 |
Correct |
269 ms |
8680 KB |
Ok |
65 |
Correct |
254 ms |
8296 KB |
Ok |
66 |
Correct |
222 ms |
8040 KB |
Ok |
67 |
Correct |
206 ms |
7784 KB |
Ok |
68 |
Correct |
245 ms |
8296 KB |
Ok |
69 |
Correct |
425 ms |
15264 KB |
Ok |
70 |
Correct |
428 ms |
15720 KB |
Ok |
71 |
Correct |
430 ms |
15208 KB |
Ok |
72 |
Correct |
426 ms |
15244 KB |
Ok |
73 |
Correct |
433 ms |
15464 KB |
Ok |
74 |
Correct |
424 ms |
15080 KB |
Ok |
75 |
Correct |
404 ms |
15336 KB |
Ok |
76 |
Correct |
425 ms |
15336 KB |
Ok |
77 |
Correct |
424 ms |
15208 KB |
Ok |
78 |
Correct |
440 ms |
15144 KB |
Ok |
79 |
Correct |
431 ms |
15744 KB |
Ok |
80 |
Correct |
420 ms |
15464 KB |
Ok |
81 |
Correct |
414 ms |
15564 KB |
Ok |
82 |
Correct |
437 ms |
15464 KB |
Ok |
83 |
Correct |
443 ms |
15464 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
4204 KB |
Ok |
2 |
Correct |
15 ms |
4204 KB |
Ok |
3 |
Correct |
16 ms |
4224 KB |
Ok |
4 |
Correct |
16 ms |
4208 KB |
Ok |
5 |
Correct |
17 ms |
4204 KB |
Ok |
6 |
Correct |
16 ms |
4204 KB |
Ok |
7 |
Correct |
16 ms |
4224 KB |
Ok |
8 |
Correct |
16 ms |
4224 KB |
Ok |
9 |
Correct |
17 ms |
4332 KB |
Ok |
10 |
Correct |
16 ms |
4204 KB |
Ok |
11 |
Correct |
16 ms |
4204 KB |
Ok |
12 |
Correct |
17 ms |
4204 KB |
Ok |
13 |
Correct |
10 ms |
4204 KB |
Ok |
14 |
Correct |
12 ms |
4204 KB |
Ok |
15 |
Correct |
13 ms |
4204 KB |
Ok |
16 |
Correct |
13 ms |
4204 KB |
Ok |
17 |
Correct |
14 ms |
4332 KB |
Ok |
18 |
Correct |
26 ms |
4460 KB |
Ok |
19 |
Correct |
49 ms |
5228 KB |
Ok |
20 |
Correct |
33 ms |
4588 KB |
Ok |
21 |
Correct |
53 ms |
5356 KB |
Ok |
22 |
Correct |
47 ms |
4844 KB |
Ok |
23 |
Correct |
5 ms |
4204 KB |
Ok |
24 |
Correct |
9 ms |
4204 KB |
Ok |
25 |
Correct |
10 ms |
4204 KB |
Ok |
26 |
Correct |
10 ms |
4204 KB |
Ok |
27 |
Correct |
11 ms |
4204 KB |
Ok |
28 |
Correct |
13 ms |
4332 KB |
Ok |
29 |
Correct |
11 ms |
4204 KB |
Ok |
30 |
Correct |
12 ms |
4204 KB |
Ok |
31 |
Correct |
13 ms |
4204 KB |
Ok |
32 |
Correct |
12 ms |
4204 KB |
Ok |
33 |
Correct |
11 ms |
4204 KB |
Ok |
34 |
Correct |
11 ms |
4204 KB |
Ok |
35 |
Correct |
12 ms |
4204 KB |
Ok |
36 |
Correct |
13 ms |
4204 KB |
Ok |
37 |
Correct |
14 ms |
4204 KB |
Ok |
38 |
Correct |
15 ms |
4204 KB |
Ok |
39 |
Correct |
348 ms |
15332 KB |
Ok |
40 |
Correct |
294 ms |
15844 KB |
Ok |
41 |
Correct |
541 ms |
18020 KB |
Ok |
42 |
Correct |
417 ms |
18020 KB |
Ok |
43 |
Correct |
292 ms |
11880 KB |
Ok |
44 |
Correct |
457 ms |
18532 KB |
Ok |
45 |
Correct |
29 ms |
4332 KB |
Ok |
46 |
Correct |
27 ms |
4460 KB |
Ok |
47 |
Correct |
27 ms |
4332 KB |
Ok |
48 |
Correct |
29 ms |
4460 KB |
Ok |
49 |
Correct |
26 ms |
4332 KB |
Ok |
50 |
Correct |
27 ms |
4332 KB |
Ok |
51 |
Correct |
26 ms |
4332 KB |
Ok |
52 |
Correct |
27 ms |
4332 KB |
Ok |
53 |
Correct |
27 ms |
4332 KB |
Ok |
54 |
Correct |
27 ms |
4332 KB |
Ok |
55 |
Correct |
34 ms |
4588 KB |
Ok |
56 |
Correct |
34 ms |
4588 KB |
Ok |
57 |
Correct |
35 ms |
4588 KB |
Ok |
58 |
Correct |
33 ms |
4588 KB |
Ok |
59 |
Correct |
34 ms |
4588 KB |
Ok |
60 |
Correct |
33 ms |
4588 KB |
Ok |
61 |
Correct |
36 ms |
4844 KB |
Ok |
62 |
Correct |
32 ms |
4588 KB |
Ok |
63 |
Correct |
34 ms |
4608 KB |
Ok |
64 |
Correct |
34 ms |
4588 KB |
Ok |
65 |
Correct |
248 ms |
8040 KB |
Ok |
66 |
Correct |
268 ms |
8424 KB |
Ok |
67 |
Correct |
266 ms |
8296 KB |
Ok |
68 |
Correct |
213 ms |
7656 KB |
Ok |
69 |
Correct |
257 ms |
8296 KB |
Ok |
70 |
Correct |
251 ms |
8168 KB |
Ok |
71 |
Correct |
217 ms |
7656 KB |
Ok |
72 |
Correct |
210 ms |
7784 KB |
Ok |
73 |
Correct |
286 ms |
8680 KB |
Ok |
74 |
Correct |
238 ms |
8040 KB |
Ok |
75 |
Correct |
269 ms |
8680 KB |
Ok |
76 |
Correct |
254 ms |
8296 KB |
Ok |
77 |
Correct |
222 ms |
8040 KB |
Ok |
78 |
Correct |
206 ms |
7784 KB |
Ok |
79 |
Correct |
245 ms |
8296 KB |
Ok |
80 |
Correct |
425 ms |
15264 KB |
Ok |
81 |
Correct |
428 ms |
15720 KB |
Ok |
82 |
Correct |
430 ms |
15208 KB |
Ok |
83 |
Correct |
426 ms |
15244 KB |
Ok |
84 |
Correct |
433 ms |
15464 KB |
Ok |
85 |
Correct |
424 ms |
15080 KB |
Ok |
86 |
Correct |
404 ms |
15336 KB |
Ok |
87 |
Correct |
425 ms |
15336 KB |
Ok |
88 |
Correct |
424 ms |
15208 KB |
Ok |
89 |
Correct |
440 ms |
15144 KB |
Ok |
90 |
Correct |
431 ms |
15744 KB |
Ok |
91 |
Correct |
420 ms |
15464 KB |
Ok |
92 |
Correct |
414 ms |
15564 KB |
Ok |
93 |
Correct |
437 ms |
15464 KB |
Ok |
94 |
Correct |
443 ms |
15464 KB |
Ok |
95 |
Correct |
596 ms |
13924 KB |
Ok |
96 |
Correct |
837 ms |
18780 KB |
Ok |
97 |
Correct |
793 ms |
17004 KB |
Ok |
98 |
Correct |
623 ms |
15280 KB |
Ok |
99 |
Correct |
702 ms |
15708 KB |
Ok |
100 |
Correct |
721 ms |
16476 KB |
Ok |
101 |
Correct |
739 ms |
16732 KB |
Ok |
102 |
Correct |
709 ms |
16348 KB |
Ok |
103 |
Correct |
703 ms |
17116 KB |
Ok |
104 |
Correct |
838 ms |
18176 KB |
Ok |
105 |
Correct |
799 ms |
18164 KB |
Ok |
106 |
Correct |
677 ms |
16732 KB |
Ok |
107 |
Correct |
785 ms |
17372 KB |
Ok |
108 |
Correct |
836 ms |
18496 KB |
Ok |
109 |
Correct |
744 ms |
18012 KB |
Ok |
110 |
Correct |
1726 ms |
49424 KB |
Ok |
111 |
Correct |
1779 ms |
51164 KB |
Ok |
112 |
Correct |
1824 ms |
51432 KB |
Ok |
113 |
Correct |
1721 ms |
49884 KB |
Ok |
114 |
Correct |
1768 ms |
51760 KB |
Ok |
115 |
Correct |
1761 ms |
51292 KB |
Ok |
116 |
Correct |
1748 ms |
51796 KB |
Ok |
117 |
Correct |
1738 ms |
50300 KB |
Ok |
118 |
Correct |
1750 ms |
51816 KB |
Ok |
119 |
Correct |
1780 ms |
49884 KB |
Ok |
120 |
Correct |
1779 ms |
50396 KB |
Ok |
121 |
Correct |
1743 ms |
50012 KB |
Ok |
122 |
Correct |
1734 ms |
50780 KB |
Ok |
123 |
Correct |
1784 ms |
50932 KB |
Ok |
124 |
Correct |
1707 ms |
51932 KB |
Ok |
125 |
Correct |
1754 ms |
33500 KB |
Ok |