#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],n,bit[MAXN];
vector<int> mid[MAXN];
int query(int now){
int ret=0;
for(int i=now;i>0;i-=(i&(-i)))ret+=bit[i];
return ret;
}
void update(int now,int val){
for(int i=now;i<=n;i+=(i&(-i)))bit[i]+=val;
}
int binser(int x){
int now=0;
for(int i=17;i>=0;i--){
if(now+(1<<i)<=n && bit[now+(1<<i)]<x){
now+=(1<<i);
x-=bit[now];
}
}
return now+1;
}
int tengah(int x,int y){
int L=query(x-1)+1,R=query(y),T;
T=(L+R)/2;
return binser(T);
}
void Solve(int N) {
int prev=0,tmpL=1,tmpR=N+1,nxt,sudah=0;
n=N;
vector<int> v;
for(int i=1;i<=2*N;i++)v.push_back(i);
for(auto i : v){
if(tmpL==N+1 || Query(i)==prev){
arr[tmpR]=i;
lo[tmpR]=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]);
update(tmpL-1,-1);
arr[tmpL-1]=0;
sudah++;
}
tmpR++;
}
else{
update(tmpL,1);
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;
res[now]=i;
if(query(hi[now])-query(lo[now]-1)>1)mid[tengah(lo[now],hi[now])].push_back(now);
else{
sudah++;
res[now]=binser(query(hi[now]));
Answer(arr[now],arr[res[now]]);
update(res[now],-1);
arr[now]=0;arr[res[now]]=0;
}
}
else{
lo[now]=i+1;
if(query(hi[now])-query(lo[now]-1)>1)mid[tengah(lo[now],hi[now])].push_back(now);
else{
sudah++;
res[now]=binser(query(hi[now]));
Answer(arr[now],arr[res[now]]);
update(res[now],-1);
arr[now]=0;arr[res[now]]=0;
}
}
}
else{
if(nxt==prev){
lo[now]=i+1;
if(query(hi[now])-query(lo[now]-1)>1)mid[tengah(lo[now],hi[now])].push_back(now);
else{
sudah++;
res[now]=binser(query(hi[now]));
Answer(arr[now],arr[res[now]]);
update(res[now],-1);
arr[now]=0;arr[res[now]]=0;
}
}
else{
hi[now]=i;
res[now]=i;
if(query(hi[now])-query(lo[now]-1)>1)mid[tengah(lo[now],hi[now])].push_back(now);
else{
sudah++;
res[now]=binser(query(hi[now]));
Answer(arr[now],arr[res[now]]);
update(res[now],-1);
arr[now]=0;arr[res[now]]=0;
}
}
}
if(sudah==N)return;
prev=nxt;
}
}
prefix=1-prefix;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2296 KB |
Output is correct |
2 |
Correct |
3 ms |
2296 KB |
Output is correct |
3 |
Correct |
4 ms |
2424 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2424 KB |
Output is correct |
2 |
Correct |
7 ms |
2552 KB |
Output is correct |
3 |
Correct |
11 ms |
2856 KB |
Output is correct |
4 |
Correct |
21 ms |
3384 KB |
Output is correct |
5 |
Correct |
51 ms |
4600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2296 KB |
Output is correct |
2 |
Correct |
3 ms |
2296 KB |
Output is correct |
3 |
Correct |
4 ms |
2424 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
5 ms |
2424 KB |
Output is correct |
6 |
Correct |
7 ms |
2552 KB |
Output is correct |
7 |
Correct |
11 ms |
2856 KB |
Output is correct |
8 |
Correct |
21 ms |
3384 KB |
Output is correct |
9 |
Correct |
51 ms |
4600 KB |
Output is correct |
10 |
Correct |
5 ms |
2552 KB |
Output is correct |
11 |
Correct |
33 ms |
3464 KB |
Output is correct |
12 |
Correct |
52 ms |
3960 KB |
Output is correct |
13 |
Correct |
15 ms |
3576 KB |
Output is correct |
14 |
Correct |
34 ms |
4472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2296 KB |
Output is correct |
2 |
Correct |
3 ms |
2296 KB |
Output is correct |
3 |
Correct |
4 ms |
2424 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
5 ms |
2424 KB |
Output is correct |
6 |
Correct |
7 ms |
2552 KB |
Output is correct |
7 |
Correct |
11 ms |
2856 KB |
Output is correct |
8 |
Correct |
21 ms |
3384 KB |
Output is correct |
9 |
Correct |
51 ms |
4600 KB |
Output is correct |
10 |
Correct |
5 ms |
2552 KB |
Output is correct |
11 |
Correct |
33 ms |
3464 KB |
Output is correct |
12 |
Correct |
52 ms |
3960 KB |
Output is correct |
13 |
Correct |
15 ms |
3576 KB |
Output is correct |
14 |
Correct |
34 ms |
4472 KB |
Output is correct |
15 |
Correct |
161 ms |
6404 KB |
Output is correct |
16 |
Correct |
157 ms |
6504 KB |
Output is correct |
17 |
Correct |
36 ms |
5484 KB |
Output is correct |
18 |
Correct |
89 ms |
8816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2296 KB |
Output is correct |
2 |
Correct |
3 ms |
2296 KB |
Output is correct |
3 |
Correct |
4 ms |
2424 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
5 ms |
2424 KB |
Output is correct |
6 |
Correct |
7 ms |
2552 KB |
Output is correct |
7 |
Correct |
11 ms |
2856 KB |
Output is correct |
8 |
Correct |
21 ms |
3384 KB |
Output is correct |
9 |
Correct |
51 ms |
4600 KB |
Output is correct |
10 |
Correct |
5 ms |
2552 KB |
Output is correct |
11 |
Correct |
33 ms |
3464 KB |
Output is correct |
12 |
Correct |
52 ms |
3960 KB |
Output is correct |
13 |
Correct |
15 ms |
3576 KB |
Output is correct |
14 |
Correct |
34 ms |
4472 KB |
Output is correct |
15 |
Correct |
161 ms |
6404 KB |
Output is correct |
16 |
Correct |
157 ms |
6504 KB |
Output is correct |
17 |
Correct |
36 ms |
5484 KB |
Output is correct |
18 |
Correct |
89 ms |
8816 KB |
Output is correct |
19 |
Correct |
164 ms |
6556 KB |
Output is correct |
20 |
Correct |
163 ms |
6560 KB |
Output is correct |
21 |
Correct |
35 ms |
5616 KB |
Output is correct |
22 |
Correct |
91 ms |
8944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2296 KB |
Output is correct |
2 |
Correct |
3 ms |
2296 KB |
Output is correct |
3 |
Correct |
4 ms |
2424 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
5 ms |
2424 KB |
Output is correct |
6 |
Correct |
7 ms |
2552 KB |
Output is correct |
7 |
Correct |
11 ms |
2856 KB |
Output is correct |
8 |
Correct |
21 ms |
3384 KB |
Output is correct |
9 |
Correct |
51 ms |
4600 KB |
Output is correct |
10 |
Correct |
5 ms |
2552 KB |
Output is correct |
11 |
Correct |
33 ms |
3464 KB |
Output is correct |
12 |
Correct |
52 ms |
3960 KB |
Output is correct |
13 |
Correct |
15 ms |
3576 KB |
Output is correct |
14 |
Correct |
34 ms |
4472 KB |
Output is correct |
15 |
Correct |
161 ms |
6404 KB |
Output is correct |
16 |
Correct |
157 ms |
6504 KB |
Output is correct |
17 |
Correct |
36 ms |
5484 KB |
Output is correct |
18 |
Correct |
89 ms |
8816 KB |
Output is correct |
19 |
Correct |
164 ms |
6556 KB |
Output is correct |
20 |
Correct |
163 ms |
6560 KB |
Output is correct |
21 |
Correct |
35 ms |
5616 KB |
Output is correct |
22 |
Correct |
91 ms |
8944 KB |
Output is correct |
23 |
Correct |
171 ms |
6720 KB |
Output is correct |
24 |
Correct |
171 ms |
6716 KB |
Output is correct |
25 |
Correct |
36 ms |
5756 KB |
Output is correct |
26 |
Correct |
93 ms |
8948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2296 KB |
Output is correct |
2 |
Correct |
3 ms |
2296 KB |
Output is correct |
3 |
Correct |
4 ms |
2424 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
5 ms |
2424 KB |
Output is correct |
6 |
Correct |
7 ms |
2552 KB |
Output is correct |
7 |
Correct |
11 ms |
2856 KB |
Output is correct |
8 |
Correct |
21 ms |
3384 KB |
Output is correct |
9 |
Correct |
51 ms |
4600 KB |
Output is correct |
10 |
Correct |
5 ms |
2552 KB |
Output is correct |
11 |
Correct |
33 ms |
3464 KB |
Output is correct |
12 |
Correct |
52 ms |
3960 KB |
Output is correct |
13 |
Correct |
15 ms |
3576 KB |
Output is correct |
14 |
Correct |
34 ms |
4472 KB |
Output is correct |
15 |
Correct |
161 ms |
6404 KB |
Output is correct |
16 |
Correct |
157 ms |
6504 KB |
Output is correct |
17 |
Correct |
36 ms |
5484 KB |
Output is correct |
18 |
Correct |
89 ms |
8816 KB |
Output is correct |
19 |
Correct |
164 ms |
6556 KB |
Output is correct |
20 |
Correct |
163 ms |
6560 KB |
Output is correct |
21 |
Correct |
35 ms |
5616 KB |
Output is correct |
22 |
Correct |
91 ms |
8944 KB |
Output is correct |
23 |
Correct |
171 ms |
6720 KB |
Output is correct |
24 |
Correct |
171 ms |
6716 KB |
Output is correct |
25 |
Correct |
36 ms |
5756 KB |
Output is correct |
26 |
Correct |
93 ms |
8948 KB |
Output is correct |
27 |
Correct |
172 ms |
6772 KB |
Output is correct |
28 |
Correct |
173 ms |
6768 KB |
Output is correct |
29 |
Correct |
38 ms |
5792 KB |
Output is correct |
30 |
Correct |
95 ms |
9200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2296 KB |
Output is correct |
2 |
Correct |
3 ms |
2296 KB |
Output is correct |
3 |
Correct |
4 ms |
2424 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
5 ms |
2424 KB |
Output is correct |
6 |
Correct |
7 ms |
2552 KB |
Output is correct |
7 |
Correct |
11 ms |
2856 KB |
Output is correct |
8 |
Correct |
21 ms |
3384 KB |
Output is correct |
9 |
Correct |
51 ms |
4600 KB |
Output is correct |
10 |
Correct |
5 ms |
2552 KB |
Output is correct |
11 |
Correct |
33 ms |
3464 KB |
Output is correct |
12 |
Correct |
52 ms |
3960 KB |
Output is correct |
13 |
Correct |
15 ms |
3576 KB |
Output is correct |
14 |
Correct |
34 ms |
4472 KB |
Output is correct |
15 |
Correct |
161 ms |
6404 KB |
Output is correct |
16 |
Correct |
157 ms |
6504 KB |
Output is correct |
17 |
Correct |
36 ms |
5484 KB |
Output is correct |
18 |
Correct |
89 ms |
8816 KB |
Output is correct |
19 |
Correct |
164 ms |
6556 KB |
Output is correct |
20 |
Correct |
163 ms |
6560 KB |
Output is correct |
21 |
Correct |
35 ms |
5616 KB |
Output is correct |
22 |
Correct |
91 ms |
8944 KB |
Output is correct |
23 |
Correct |
171 ms |
6720 KB |
Output is correct |
24 |
Correct |
171 ms |
6716 KB |
Output is correct |
25 |
Correct |
36 ms |
5756 KB |
Output is correct |
26 |
Correct |
93 ms |
8948 KB |
Output is correct |
27 |
Correct |
172 ms |
6772 KB |
Output is correct |
28 |
Correct |
173 ms |
6768 KB |
Output is correct |
29 |
Correct |
38 ms |
5792 KB |
Output is correct |
30 |
Correct |
95 ms |
9200 KB |
Output is correct |
31 |
Correct |
178 ms |
6884 KB |
Output is correct |
32 |
Correct |
179 ms |
6944 KB |
Output is correct |
33 |
Correct |
37 ms |
5828 KB |
Output is correct |
34 |
Incorrect |
95 ms |
9196 KB |
Wrong Answer [2] |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2296 KB |
Output is correct |
2 |
Correct |
3 ms |
2296 KB |
Output is correct |
3 |
Correct |
4 ms |
2424 KB |
Output is correct |
4 |
Correct |
4 ms |
2424 KB |
Output is correct |
5 |
Correct |
5 ms |
2424 KB |
Output is correct |
6 |
Correct |
7 ms |
2552 KB |
Output is correct |
7 |
Correct |
11 ms |
2856 KB |
Output is correct |
8 |
Correct |
21 ms |
3384 KB |
Output is correct |
9 |
Correct |
51 ms |
4600 KB |
Output is correct |
10 |
Correct |
5 ms |
2552 KB |
Output is correct |
11 |
Correct |
33 ms |
3464 KB |
Output is correct |
12 |
Correct |
52 ms |
3960 KB |
Output is correct |
13 |
Correct |
15 ms |
3576 KB |
Output is correct |
14 |
Correct |
34 ms |
4472 KB |
Output is correct |
15 |
Correct |
161 ms |
6404 KB |
Output is correct |
16 |
Correct |
157 ms |
6504 KB |
Output is correct |
17 |
Correct |
36 ms |
5484 KB |
Output is correct |
18 |
Correct |
89 ms |
8816 KB |
Output is correct |
19 |
Correct |
164 ms |
6556 KB |
Output is correct |
20 |
Correct |
163 ms |
6560 KB |
Output is correct |
21 |
Correct |
35 ms |
5616 KB |
Output is correct |
22 |
Correct |
91 ms |
8944 KB |
Output is correct |
23 |
Correct |
171 ms |
6720 KB |
Output is correct |
24 |
Correct |
171 ms |
6716 KB |
Output is correct |
25 |
Correct |
36 ms |
5756 KB |
Output is correct |
26 |
Correct |
93 ms |
8948 KB |
Output is correct |
27 |
Correct |
172 ms |
6772 KB |
Output is correct |
28 |
Correct |
173 ms |
6768 KB |
Output is correct |
29 |
Correct |
38 ms |
5792 KB |
Output is correct |
30 |
Correct |
95 ms |
9200 KB |
Output is correct |
31 |
Correct |
178 ms |
6884 KB |
Output is correct |
32 |
Correct |
179 ms |
6944 KB |
Output is correct |
33 |
Correct |
37 ms |
5828 KB |
Output is correct |
34 |
Incorrect |
95 ms |
9196 KB |
Wrong Answer [2] |