#include <bits/stdc++.h>
#include <minerals.h>
using namespace std;
#define ll long long
// #define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define RREP1(i, n) for (int i = (n); i >= 1; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define pb push_back
#define pii pair<int, int>
#define f first
#define s second
const ll maxn = 5e5+5;
const ll inf = (1ll<<60);
const ll mod = 1000992299;
const long double p = 0.40001;
int ou;
void run(vector<int> &L, vector<int> &R, bool x){
if (SZ(L) == 1 && SZ(R) == 1){
Answer(L[0], R[0]);
return;
}
int mid = SZ(L)*p, ret;
vector<int> lll, lr, rl, rr;
if (SZ(L) == 2 && SZ(R) == 2){
if (x == 0){
ou = Query(L[0]);
ret = Query(R[0]);
if (ret != ou){
Answer(L[0], R[1]);
Answer(L[1], R[0]);
}
else{
Answer(L[0], R[0]);
Answer(L[1], R[1]);
}
}
else {
ou = Query(L[0]);
ret = Query(R[0]);
if (ret == ou){
Answer(L[0], R[1]);
Answer(L[1], R[0]);
}
else{
Answer(L[0], R[0]);
Answer(L[1], R[1]);
}
}
return;
}
REP(i, mid){
ou = Query(L[i]);
lll.pb(L[i]);
}
FOR(i, mid, SZ(L)){
rl.pb(L[i]);
}
if (x == 0){
REP(i, SZ(R)){
if (SZ(lll) == SZ(lr)){
rr.pb(R[i]);
continue;
}
if (SZ(rl) == SZ(rr)){
lr.pb(R[i]);
continue;
}
ret = Query(R[i]);
if (ret == ou) lr.pb(R[i]);
else rr.pb(R[i]);
ou = ret;
}
run(lll, lr, 1);
run(rl, rr, 0);
}
else {
REP(i, SZ(R)){
if (SZ(lll) == SZ(lr)){
rr.pb(R[i]);
continue;
}
if (SZ(rl) == SZ(rr)){
lr.pb(R[i]);
continue;
}
ret = Query(R[i]);
if (ret != ou) lr.pb(R[i]);
else rr.pb(R[i]);
ou = ret;
}
run(lll, lr, 0);
run(rl, rr, 1);
}
}
void Solve(int N){
vector<int> a, b;
//REP1(i, N) a.pb(i);
//FOR(i, N+1, 2*N+1) b.pb(i);
int ret, prev = 0;
REP1(i, 2*N){
ret = Query(i);
if (ret != prev) {
a.pb(i);
prev = ret;
}
else {
b.pb(i);
}
}
ou = prev;
random_shuffle(ALL(a));
random_shuffle(ALL(b));
//REP(i, SZ(a)) Query(a[i]);
run(a, b, 1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
600 KB |
Output is correct |
4 |
Correct |
7 ms |
760 KB |
Output is correct |
5 |
Correct |
10 ms |
1368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
600 KB |
Output is correct |
8 |
Correct |
7 ms |
760 KB |
Output is correct |
9 |
Correct |
10 ms |
1368 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
996 KB |
Output is correct |
12 |
Correct |
10 ms |
1368 KB |
Output is correct |
13 |
Correct |
11 ms |
1780 KB |
Output is correct |
14 |
Correct |
10 ms |
1564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
600 KB |
Output is correct |
8 |
Correct |
7 ms |
760 KB |
Output is correct |
9 |
Correct |
10 ms |
1368 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
996 KB |
Output is correct |
12 |
Correct |
10 ms |
1368 KB |
Output is correct |
13 |
Correct |
11 ms |
1780 KB |
Output is correct |
14 |
Correct |
10 ms |
1564 KB |
Output is correct |
15 |
Correct |
27 ms |
2840 KB |
Output is correct |
16 |
Correct |
27 ms |
2620 KB |
Output is correct |
17 |
Correct |
26 ms |
2732 KB |
Output is correct |
18 |
Correct |
26 ms |
2460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
600 KB |
Output is correct |
8 |
Correct |
7 ms |
760 KB |
Output is correct |
9 |
Correct |
10 ms |
1368 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
996 KB |
Output is correct |
12 |
Correct |
10 ms |
1368 KB |
Output is correct |
13 |
Correct |
11 ms |
1780 KB |
Output is correct |
14 |
Correct |
10 ms |
1564 KB |
Output is correct |
15 |
Correct |
27 ms |
2840 KB |
Output is correct |
16 |
Correct |
27 ms |
2620 KB |
Output is correct |
17 |
Correct |
26 ms |
2732 KB |
Output is correct |
18 |
Correct |
26 ms |
2460 KB |
Output is correct |
19 |
Correct |
27 ms |
2780 KB |
Output is correct |
20 |
Correct |
30 ms |
2784 KB |
Output is correct |
21 |
Correct |
26 ms |
2668 KB |
Output is correct |
22 |
Correct |
26 ms |
2752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
600 KB |
Output is correct |
8 |
Correct |
7 ms |
760 KB |
Output is correct |
9 |
Correct |
10 ms |
1368 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
996 KB |
Output is correct |
12 |
Correct |
10 ms |
1368 KB |
Output is correct |
13 |
Correct |
11 ms |
1780 KB |
Output is correct |
14 |
Correct |
10 ms |
1564 KB |
Output is correct |
15 |
Correct |
27 ms |
2840 KB |
Output is correct |
16 |
Correct |
27 ms |
2620 KB |
Output is correct |
17 |
Correct |
26 ms |
2732 KB |
Output is correct |
18 |
Correct |
26 ms |
2460 KB |
Output is correct |
19 |
Correct |
27 ms |
2780 KB |
Output is correct |
20 |
Correct |
30 ms |
2784 KB |
Output is correct |
21 |
Correct |
26 ms |
2668 KB |
Output is correct |
22 |
Correct |
26 ms |
2752 KB |
Output is correct |
23 |
Correct |
30 ms |
2780 KB |
Output is correct |
24 |
Correct |
28 ms |
2796 KB |
Output is correct |
25 |
Correct |
29 ms |
2924 KB |
Output is correct |
26 |
Correct |
29 ms |
2620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
600 KB |
Output is correct |
8 |
Correct |
7 ms |
760 KB |
Output is correct |
9 |
Correct |
10 ms |
1368 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
996 KB |
Output is correct |
12 |
Correct |
10 ms |
1368 KB |
Output is correct |
13 |
Correct |
11 ms |
1780 KB |
Output is correct |
14 |
Correct |
10 ms |
1564 KB |
Output is correct |
15 |
Correct |
27 ms |
2840 KB |
Output is correct |
16 |
Correct |
27 ms |
2620 KB |
Output is correct |
17 |
Correct |
26 ms |
2732 KB |
Output is correct |
18 |
Correct |
26 ms |
2460 KB |
Output is correct |
19 |
Correct |
27 ms |
2780 KB |
Output is correct |
20 |
Correct |
30 ms |
2784 KB |
Output is correct |
21 |
Correct |
26 ms |
2668 KB |
Output is correct |
22 |
Correct |
26 ms |
2752 KB |
Output is correct |
23 |
Correct |
30 ms |
2780 KB |
Output is correct |
24 |
Correct |
28 ms |
2796 KB |
Output is correct |
25 |
Correct |
29 ms |
2924 KB |
Output is correct |
26 |
Correct |
29 ms |
2620 KB |
Output is correct |
27 |
Correct |
28 ms |
2808 KB |
Output is correct |
28 |
Correct |
28 ms |
2896 KB |
Output is correct |
29 |
Correct |
29 ms |
3300 KB |
Output is correct |
30 |
Correct |
27 ms |
2820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
600 KB |
Output is correct |
8 |
Correct |
7 ms |
760 KB |
Output is correct |
9 |
Correct |
10 ms |
1368 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
996 KB |
Output is correct |
12 |
Correct |
10 ms |
1368 KB |
Output is correct |
13 |
Correct |
11 ms |
1780 KB |
Output is correct |
14 |
Correct |
10 ms |
1564 KB |
Output is correct |
15 |
Correct |
27 ms |
2840 KB |
Output is correct |
16 |
Correct |
27 ms |
2620 KB |
Output is correct |
17 |
Correct |
26 ms |
2732 KB |
Output is correct |
18 |
Correct |
26 ms |
2460 KB |
Output is correct |
19 |
Correct |
27 ms |
2780 KB |
Output is correct |
20 |
Correct |
30 ms |
2784 KB |
Output is correct |
21 |
Correct |
26 ms |
2668 KB |
Output is correct |
22 |
Correct |
26 ms |
2752 KB |
Output is correct |
23 |
Correct |
30 ms |
2780 KB |
Output is correct |
24 |
Correct |
28 ms |
2796 KB |
Output is correct |
25 |
Correct |
29 ms |
2924 KB |
Output is correct |
26 |
Correct |
29 ms |
2620 KB |
Output is correct |
27 |
Correct |
28 ms |
2808 KB |
Output is correct |
28 |
Correct |
28 ms |
2896 KB |
Output is correct |
29 |
Correct |
29 ms |
3300 KB |
Output is correct |
30 |
Correct |
27 ms |
2820 KB |
Output is correct |
31 |
Correct |
30 ms |
2924 KB |
Output is correct |
32 |
Correct |
38 ms |
2960 KB |
Output is correct |
33 |
Correct |
29 ms |
3308 KB |
Output is correct |
34 |
Correct |
30 ms |
3032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
600 KB |
Output is correct |
8 |
Correct |
7 ms |
760 KB |
Output is correct |
9 |
Correct |
10 ms |
1368 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
996 KB |
Output is correct |
12 |
Correct |
10 ms |
1368 KB |
Output is correct |
13 |
Correct |
11 ms |
1780 KB |
Output is correct |
14 |
Correct |
10 ms |
1564 KB |
Output is correct |
15 |
Correct |
27 ms |
2840 KB |
Output is correct |
16 |
Correct |
27 ms |
2620 KB |
Output is correct |
17 |
Correct |
26 ms |
2732 KB |
Output is correct |
18 |
Correct |
26 ms |
2460 KB |
Output is correct |
19 |
Correct |
27 ms |
2780 KB |
Output is correct |
20 |
Correct |
30 ms |
2784 KB |
Output is correct |
21 |
Correct |
26 ms |
2668 KB |
Output is correct |
22 |
Correct |
26 ms |
2752 KB |
Output is correct |
23 |
Correct |
30 ms |
2780 KB |
Output is correct |
24 |
Correct |
28 ms |
2796 KB |
Output is correct |
25 |
Correct |
29 ms |
2924 KB |
Output is correct |
26 |
Correct |
29 ms |
2620 KB |
Output is correct |
27 |
Correct |
28 ms |
2808 KB |
Output is correct |
28 |
Correct |
28 ms |
2896 KB |
Output is correct |
29 |
Correct |
29 ms |
3300 KB |
Output is correct |
30 |
Correct |
27 ms |
2820 KB |
Output is correct |
31 |
Correct |
30 ms |
2924 KB |
Output is correct |
32 |
Correct |
38 ms |
2960 KB |
Output is correct |
33 |
Correct |
29 ms |
3308 KB |
Output is correct |
34 |
Correct |
30 ms |
3032 KB |
Output is correct |
35 |
Correct |
30 ms |
3072 KB |
Output is correct |
36 |
Correct |
33 ms |
3068 KB |
Output is correct |
37 |
Correct |
40 ms |
3136 KB |
Output is correct |
38 |
Correct |
29 ms |
3364 KB |
Output is correct |