#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
const double RAT=1.618;
const int MAXN=86005;
int lo[MAXN],hi[MAXN],arr[MAXN],res[MAXN];
vector<int> mid[MAXN];
int tengah(int x,int y){
return (x+y)/2;
}
void Solve(int N) {
int prev=0,tmpL=1,tmpR=N+1,nxt,sudah=0,C=0;
vector<int> v;
for(int i=1;i<=2*N;i++)v.push_back(i);
random_shuffle(v.begin(),v.end());
for(auto i : v){
if(tmpL==N+1 || Query(i)==prev){
arr[tmpR]=i;
lo[tmpR]=C+1;
hi[tmpR]=tmpL-1;
if(lo[tmpR]<hi[tmpR])mid[tengah(lo[tmpR],hi[tmpR])].push_back(tmpR);
else{
Answer(i,arr[tmpL-1]);
arr[tmpL-1]=0;
sudah++;
}
tmpR++;
if(tmpL==tmpR-N)C=tmpL-1;
}
else{
arr[tmpL]=i;
tmpL++;
prev++;
}
}
if(sudah==N)return;
int prefix=0;
while(sudah<N){
for(int i=1;i<=N;i++){
if(arr[i])prev=Query(arr[i]);
while(!mid[i].empty()){
int now=mid[i].back();
mid[i].pop_back();
nxt=Query(arr[now]);
if(prefix){
if(nxt==prev){ //sudah ada
hi[now]=i-1;
res[now]=i;
if(lo[now]<=hi[now])mid[tengah(lo[now],hi[now])].push_back(now);
else{
sudah++;
Answer(arr[now],arr[res[now]]);
arr[now]=0;arr[res[now]]=0;
}
}
else{
lo[now]=i+1;
if(lo[now]<=hi[now])mid[tengah(lo[now],hi[now])].push_back(now);
else{
sudah++;
Answer(arr[now],arr[res[now]]);
arr[now]=0;arr[res[now]]=0;
}
}
}
else{
if(nxt==prev){
lo[now]=i+1;
if(lo[now]<=hi[now])mid[tengah(lo[now],hi[now])].push_back(now);
else{
sudah++;
Answer(arr[now],arr[res[now]]);
arr[now]=0;arr[res[now]]=0;
}
}
else{
hi[now]=i-1;
res[now]=i;
if(lo[now]<=hi[now])mid[tengah(lo[now],hi[now])].push_back(now);
else{
sudah++;
Answer(arr[now],arr[res[now]]);
arr[now]=0;arr[res[now]]=0;
}
}
}
if(sudah==N)return;
prev=nxt;
}
}
prefix=1-prefix;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2428 KB |
Output is correct |
2 |
Correct |
4 ms |
2296 KB |
Output is correct |
3 |
Correct |
3 ms |
2308 KB |
Output is correct |
4 |
Correct |
4 ms |
2340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2424 KB |
Output is correct |
2 |
Correct |
6 ms |
2552 KB |
Output is correct |
3 |
Correct |
9 ms |
2680 KB |
Output is correct |
4 |
Correct |
17 ms |
3192 KB |
Output is correct |
5 |
Correct |
32 ms |
3836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2428 KB |
Output is correct |
2 |
Correct |
4 ms |
2296 KB |
Output is correct |
3 |
Correct |
3 ms |
2308 KB |
Output is correct |
4 |
Correct |
4 ms |
2340 KB |
Output is correct |
5 |
Correct |
5 ms |
2424 KB |
Output is correct |
6 |
Correct |
6 ms |
2552 KB |
Output is correct |
7 |
Correct |
9 ms |
2680 KB |
Output is correct |
8 |
Correct |
17 ms |
3192 KB |
Output is correct |
9 |
Correct |
32 ms |
3836 KB |
Output is correct |
10 |
Correct |
5 ms |
2552 KB |
Output is correct |
11 |
Correct |
21 ms |
3356 KB |
Output is correct |
12 |
Correct |
34 ms |
3960 KB |
Output is correct |
13 |
Correct |
31 ms |
3960 KB |
Output is correct |
14 |
Correct |
32 ms |
3832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2428 KB |
Output is correct |
2 |
Correct |
4 ms |
2296 KB |
Output is correct |
3 |
Correct |
3 ms |
2308 KB |
Output is correct |
4 |
Correct |
4 ms |
2340 KB |
Output is correct |
5 |
Correct |
5 ms |
2424 KB |
Output is correct |
6 |
Correct |
6 ms |
2552 KB |
Output is correct |
7 |
Correct |
9 ms |
2680 KB |
Output is correct |
8 |
Correct |
17 ms |
3192 KB |
Output is correct |
9 |
Correct |
32 ms |
3836 KB |
Output is correct |
10 |
Correct |
5 ms |
2552 KB |
Output is correct |
11 |
Correct |
21 ms |
3356 KB |
Output is correct |
12 |
Correct |
34 ms |
3960 KB |
Output is correct |
13 |
Correct |
31 ms |
3960 KB |
Output is correct |
14 |
Correct |
32 ms |
3832 KB |
Output is correct |
15 |
Correct |
94 ms |
6444 KB |
Output is correct |
16 |
Correct |
99 ms |
6320 KB |
Output is correct |
17 |
Correct |
91 ms |
6352 KB |
Output is correct |
18 |
Correct |
94 ms |
6384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2428 KB |
Output is correct |
2 |
Correct |
4 ms |
2296 KB |
Output is correct |
3 |
Correct |
3 ms |
2308 KB |
Output is correct |
4 |
Correct |
4 ms |
2340 KB |
Output is correct |
5 |
Correct |
5 ms |
2424 KB |
Output is correct |
6 |
Correct |
6 ms |
2552 KB |
Output is correct |
7 |
Correct |
9 ms |
2680 KB |
Output is correct |
8 |
Correct |
17 ms |
3192 KB |
Output is correct |
9 |
Correct |
32 ms |
3836 KB |
Output is correct |
10 |
Correct |
5 ms |
2552 KB |
Output is correct |
11 |
Correct |
21 ms |
3356 KB |
Output is correct |
12 |
Correct |
34 ms |
3960 KB |
Output is correct |
13 |
Correct |
31 ms |
3960 KB |
Output is correct |
14 |
Correct |
32 ms |
3832 KB |
Output is correct |
15 |
Correct |
94 ms |
6444 KB |
Output is correct |
16 |
Correct |
99 ms |
6320 KB |
Output is correct |
17 |
Correct |
91 ms |
6352 KB |
Output is correct |
18 |
Correct |
94 ms |
6384 KB |
Output is correct |
19 |
Correct |
100 ms |
6384 KB |
Output is correct |
20 |
Correct |
101 ms |
6428 KB |
Output is correct |
21 |
Correct |
95 ms |
6380 KB |
Output is correct |
22 |
Correct |
98 ms |
6276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2428 KB |
Output is correct |
2 |
Correct |
4 ms |
2296 KB |
Output is correct |
3 |
Correct |
3 ms |
2308 KB |
Output is correct |
4 |
Correct |
4 ms |
2340 KB |
Output is correct |
5 |
Correct |
5 ms |
2424 KB |
Output is correct |
6 |
Correct |
6 ms |
2552 KB |
Output is correct |
7 |
Correct |
9 ms |
2680 KB |
Output is correct |
8 |
Correct |
17 ms |
3192 KB |
Output is correct |
9 |
Correct |
32 ms |
3836 KB |
Output is correct |
10 |
Correct |
5 ms |
2552 KB |
Output is correct |
11 |
Correct |
21 ms |
3356 KB |
Output is correct |
12 |
Correct |
34 ms |
3960 KB |
Output is correct |
13 |
Correct |
31 ms |
3960 KB |
Output is correct |
14 |
Correct |
32 ms |
3832 KB |
Output is correct |
15 |
Correct |
94 ms |
6444 KB |
Output is correct |
16 |
Correct |
99 ms |
6320 KB |
Output is correct |
17 |
Correct |
91 ms |
6352 KB |
Output is correct |
18 |
Correct |
94 ms |
6384 KB |
Output is correct |
19 |
Correct |
100 ms |
6384 KB |
Output is correct |
20 |
Correct |
101 ms |
6428 KB |
Output is correct |
21 |
Correct |
95 ms |
6380 KB |
Output is correct |
22 |
Correct |
98 ms |
6276 KB |
Output is correct |
23 |
Correct |
100 ms |
6500 KB |
Output is correct |
24 |
Correct |
99 ms |
6512 KB |
Output is correct |
25 |
Correct |
93 ms |
6512 KB |
Output is correct |
26 |
Correct |
100 ms |
6468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2428 KB |
Output is correct |
2 |
Correct |
4 ms |
2296 KB |
Output is correct |
3 |
Correct |
3 ms |
2308 KB |
Output is correct |
4 |
Correct |
4 ms |
2340 KB |
Output is correct |
5 |
Correct |
5 ms |
2424 KB |
Output is correct |
6 |
Correct |
6 ms |
2552 KB |
Output is correct |
7 |
Correct |
9 ms |
2680 KB |
Output is correct |
8 |
Correct |
17 ms |
3192 KB |
Output is correct |
9 |
Correct |
32 ms |
3836 KB |
Output is correct |
10 |
Correct |
5 ms |
2552 KB |
Output is correct |
11 |
Correct |
21 ms |
3356 KB |
Output is correct |
12 |
Correct |
34 ms |
3960 KB |
Output is correct |
13 |
Correct |
31 ms |
3960 KB |
Output is correct |
14 |
Correct |
32 ms |
3832 KB |
Output is correct |
15 |
Correct |
94 ms |
6444 KB |
Output is correct |
16 |
Correct |
99 ms |
6320 KB |
Output is correct |
17 |
Correct |
91 ms |
6352 KB |
Output is correct |
18 |
Correct |
94 ms |
6384 KB |
Output is correct |
19 |
Correct |
100 ms |
6384 KB |
Output is correct |
20 |
Correct |
101 ms |
6428 KB |
Output is correct |
21 |
Correct |
95 ms |
6380 KB |
Output is correct |
22 |
Correct |
98 ms |
6276 KB |
Output is correct |
23 |
Correct |
100 ms |
6500 KB |
Output is correct |
24 |
Correct |
99 ms |
6512 KB |
Output is correct |
25 |
Correct |
93 ms |
6512 KB |
Output is correct |
26 |
Correct |
100 ms |
6468 KB |
Output is correct |
27 |
Correct |
104 ms |
6728 KB |
Output is correct |
28 |
Correct |
106 ms |
6704 KB |
Output is correct |
29 |
Correct |
97 ms |
6688 KB |
Output is correct |
30 |
Correct |
102 ms |
6508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2428 KB |
Output is correct |
2 |
Correct |
4 ms |
2296 KB |
Output is correct |
3 |
Correct |
3 ms |
2308 KB |
Output is correct |
4 |
Correct |
4 ms |
2340 KB |
Output is correct |
5 |
Correct |
5 ms |
2424 KB |
Output is correct |
6 |
Correct |
6 ms |
2552 KB |
Output is correct |
7 |
Correct |
9 ms |
2680 KB |
Output is correct |
8 |
Correct |
17 ms |
3192 KB |
Output is correct |
9 |
Correct |
32 ms |
3836 KB |
Output is correct |
10 |
Correct |
5 ms |
2552 KB |
Output is correct |
11 |
Correct |
21 ms |
3356 KB |
Output is correct |
12 |
Correct |
34 ms |
3960 KB |
Output is correct |
13 |
Correct |
31 ms |
3960 KB |
Output is correct |
14 |
Correct |
32 ms |
3832 KB |
Output is correct |
15 |
Correct |
94 ms |
6444 KB |
Output is correct |
16 |
Correct |
99 ms |
6320 KB |
Output is correct |
17 |
Correct |
91 ms |
6352 KB |
Output is correct |
18 |
Correct |
94 ms |
6384 KB |
Output is correct |
19 |
Correct |
100 ms |
6384 KB |
Output is correct |
20 |
Correct |
101 ms |
6428 KB |
Output is correct |
21 |
Correct |
95 ms |
6380 KB |
Output is correct |
22 |
Correct |
98 ms |
6276 KB |
Output is correct |
23 |
Correct |
100 ms |
6500 KB |
Output is correct |
24 |
Correct |
99 ms |
6512 KB |
Output is correct |
25 |
Correct |
93 ms |
6512 KB |
Output is correct |
26 |
Correct |
100 ms |
6468 KB |
Output is correct |
27 |
Correct |
104 ms |
6728 KB |
Output is correct |
28 |
Correct |
106 ms |
6704 KB |
Output is correct |
29 |
Correct |
97 ms |
6688 KB |
Output is correct |
30 |
Correct |
102 ms |
6508 KB |
Output is correct |
31 |
Incorrect |
105 ms |
6768 KB |
Wrong Answer [2] |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2428 KB |
Output is correct |
2 |
Correct |
4 ms |
2296 KB |
Output is correct |
3 |
Correct |
3 ms |
2308 KB |
Output is correct |
4 |
Correct |
4 ms |
2340 KB |
Output is correct |
5 |
Correct |
5 ms |
2424 KB |
Output is correct |
6 |
Correct |
6 ms |
2552 KB |
Output is correct |
7 |
Correct |
9 ms |
2680 KB |
Output is correct |
8 |
Correct |
17 ms |
3192 KB |
Output is correct |
9 |
Correct |
32 ms |
3836 KB |
Output is correct |
10 |
Correct |
5 ms |
2552 KB |
Output is correct |
11 |
Correct |
21 ms |
3356 KB |
Output is correct |
12 |
Correct |
34 ms |
3960 KB |
Output is correct |
13 |
Correct |
31 ms |
3960 KB |
Output is correct |
14 |
Correct |
32 ms |
3832 KB |
Output is correct |
15 |
Correct |
94 ms |
6444 KB |
Output is correct |
16 |
Correct |
99 ms |
6320 KB |
Output is correct |
17 |
Correct |
91 ms |
6352 KB |
Output is correct |
18 |
Correct |
94 ms |
6384 KB |
Output is correct |
19 |
Correct |
100 ms |
6384 KB |
Output is correct |
20 |
Correct |
101 ms |
6428 KB |
Output is correct |
21 |
Correct |
95 ms |
6380 KB |
Output is correct |
22 |
Correct |
98 ms |
6276 KB |
Output is correct |
23 |
Correct |
100 ms |
6500 KB |
Output is correct |
24 |
Correct |
99 ms |
6512 KB |
Output is correct |
25 |
Correct |
93 ms |
6512 KB |
Output is correct |
26 |
Correct |
100 ms |
6468 KB |
Output is correct |
27 |
Correct |
104 ms |
6728 KB |
Output is correct |
28 |
Correct |
106 ms |
6704 KB |
Output is correct |
29 |
Correct |
97 ms |
6688 KB |
Output is correct |
30 |
Correct |
102 ms |
6508 KB |
Output is correct |
31 |
Incorrect |
105 ms |
6768 KB |
Wrong Answer [2] |
32 |
Halted |
0 ms |
0 KB |
- |