#include "minerals.h"
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
vector<int> a;
vector<int> belong;
vector<pair<int,int>> vec;
void go(int l,int r,vector<int> &b,int id){
if(l==r){
//Query(a[l]);
assert((int)b.size()==1);
vec.push_back({a[l],b[0]});
return;
}
int mid=(l+r)/2;
int cur=0;
for(int i=mid+1;i<=r;i++){
cur=Query(a[i]);
}
vector<int> ls,rs;
for(auto v:b){
if(belong[v]<=mid){
ls.push_back(v);
continue;
}
if((int)ls.size()==mid-l+1){
rs.push_back(v);
continue;
}
if((int)rs.size()==r-mid){
ls.push_back(v);
continue;
}
int x=Query(v);
if(id==0){
if(x!=cur){
ls.push_back(v);
}
else{
rs.push_back(v);
}
}
else{
if(x==cur){
ls.push_back(v);
}
else{
rs.push_back(v);
}
}
cur=x;
}
vector<int>().swap(b);
if(id==0){
go(l,mid,ls,0);
go(mid+1,r,rs,1);
}
else{
go(l,mid,ls,1);
go(mid+1,r,rs,0);
}
}
void Solve(int n){
vector<bool> ok(2*n+1);
int prv=0;
vector<int> ord(2*n+1);
for(int i=1;i<=2*n;i++){
ord[i]=i;
}
mt19937 rng(time(NULL));
shuffle(ord.begin()+1,ord.end(),rng);
for(int t=1;t<=2*n;t++){
int i=ord[t];
int x=Query(i);
if(x==prv+1){
ok[i]=true;
}
prv=x;
}
vector<int> b;
int cnt=-1;
belong.resize(2*n+1);
for(int t=1;t<=2*n;t++){
int i=ord[t];
if(ok[i]){
a.push_back(i);
cnt++;
}
else{
b.push_back(i);
belong[i]=cnt;
}
}
go(0,n-1,b,1);
for(auto v:vec){
Answer(v.f,v.s);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 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 |
2 ms |
600 KB |
Output is correct |
4 |
Correct |
5 ms |
856 KB |
Output is correct |
5 |
Correct |
9 ms |
1336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1336 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1028 KB |
Output is correct |
12 |
Correct |
9 ms |
1504 KB |
Output is correct |
13 |
Correct |
9 ms |
1772 KB |
Output is correct |
14 |
Correct |
9 ms |
1624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1336 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1028 KB |
Output is correct |
12 |
Correct |
9 ms |
1504 KB |
Output is correct |
13 |
Correct |
9 ms |
1772 KB |
Output is correct |
14 |
Correct |
9 ms |
1624 KB |
Output is correct |
15 |
Correct |
30 ms |
3388 KB |
Output is correct |
16 |
Correct |
27 ms |
3000 KB |
Output is correct |
17 |
Correct |
25 ms |
3072 KB |
Output is correct |
18 |
Correct |
28 ms |
2896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1336 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1028 KB |
Output is correct |
12 |
Correct |
9 ms |
1504 KB |
Output is correct |
13 |
Correct |
9 ms |
1772 KB |
Output is correct |
14 |
Correct |
9 ms |
1624 KB |
Output is correct |
15 |
Correct |
30 ms |
3388 KB |
Output is correct |
16 |
Correct |
27 ms |
3000 KB |
Output is correct |
17 |
Correct |
25 ms |
3072 KB |
Output is correct |
18 |
Correct |
28 ms |
2896 KB |
Output is correct |
19 |
Correct |
26 ms |
3144 KB |
Output is correct |
20 |
Correct |
28 ms |
3108 KB |
Output is correct |
21 |
Correct |
34 ms |
3384 KB |
Output is correct |
22 |
Correct |
27 ms |
3028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1336 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1028 KB |
Output is correct |
12 |
Correct |
9 ms |
1504 KB |
Output is correct |
13 |
Correct |
9 ms |
1772 KB |
Output is correct |
14 |
Correct |
9 ms |
1624 KB |
Output is correct |
15 |
Correct |
30 ms |
3388 KB |
Output is correct |
16 |
Correct |
27 ms |
3000 KB |
Output is correct |
17 |
Correct |
25 ms |
3072 KB |
Output is correct |
18 |
Correct |
28 ms |
2896 KB |
Output is correct |
19 |
Correct |
26 ms |
3144 KB |
Output is correct |
20 |
Correct |
28 ms |
3108 KB |
Output is correct |
21 |
Correct |
34 ms |
3384 KB |
Output is correct |
22 |
Correct |
27 ms |
3028 KB |
Output is correct |
23 |
Correct |
28 ms |
3224 KB |
Output is correct |
24 |
Correct |
29 ms |
3140 KB |
Output is correct |
25 |
Correct |
28 ms |
3132 KB |
Output is correct |
26 |
Correct |
29 ms |
2972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1336 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1028 KB |
Output is correct |
12 |
Correct |
9 ms |
1504 KB |
Output is correct |
13 |
Correct |
9 ms |
1772 KB |
Output is correct |
14 |
Correct |
9 ms |
1624 KB |
Output is correct |
15 |
Correct |
30 ms |
3388 KB |
Output is correct |
16 |
Correct |
27 ms |
3000 KB |
Output is correct |
17 |
Correct |
25 ms |
3072 KB |
Output is correct |
18 |
Correct |
28 ms |
2896 KB |
Output is correct |
19 |
Correct |
26 ms |
3144 KB |
Output is correct |
20 |
Correct |
28 ms |
3108 KB |
Output is correct |
21 |
Correct |
34 ms |
3384 KB |
Output is correct |
22 |
Correct |
27 ms |
3028 KB |
Output is correct |
23 |
Correct |
28 ms |
3224 KB |
Output is correct |
24 |
Correct |
29 ms |
3140 KB |
Output is correct |
25 |
Correct |
28 ms |
3132 KB |
Output is correct |
26 |
Correct |
29 ms |
2972 KB |
Output is correct |
27 |
Correct |
36 ms |
3148 KB |
Output is correct |
28 |
Correct |
28 ms |
3216 KB |
Output is correct |
29 |
Correct |
28 ms |
3260 KB |
Output is correct |
30 |
Correct |
28 ms |
3252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1336 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1028 KB |
Output is correct |
12 |
Correct |
9 ms |
1504 KB |
Output is correct |
13 |
Correct |
9 ms |
1772 KB |
Output is correct |
14 |
Correct |
9 ms |
1624 KB |
Output is correct |
15 |
Correct |
30 ms |
3388 KB |
Output is correct |
16 |
Correct |
27 ms |
3000 KB |
Output is correct |
17 |
Correct |
25 ms |
3072 KB |
Output is correct |
18 |
Correct |
28 ms |
2896 KB |
Output is correct |
19 |
Correct |
26 ms |
3144 KB |
Output is correct |
20 |
Correct |
28 ms |
3108 KB |
Output is correct |
21 |
Correct |
34 ms |
3384 KB |
Output is correct |
22 |
Correct |
27 ms |
3028 KB |
Output is correct |
23 |
Correct |
28 ms |
3224 KB |
Output is correct |
24 |
Correct |
29 ms |
3140 KB |
Output is correct |
25 |
Correct |
28 ms |
3132 KB |
Output is correct |
26 |
Correct |
29 ms |
2972 KB |
Output is correct |
27 |
Correct |
36 ms |
3148 KB |
Output is correct |
28 |
Correct |
28 ms |
3216 KB |
Output is correct |
29 |
Correct |
28 ms |
3260 KB |
Output is correct |
30 |
Correct |
28 ms |
3252 KB |
Output is correct |
31 |
Correct |
30 ms |
3268 KB |
Output is correct |
32 |
Correct |
31 ms |
3376 KB |
Output is correct |
33 |
Correct |
28 ms |
3492 KB |
Output is correct |
34 |
Correct |
28 ms |
3104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1336 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
1028 KB |
Output is correct |
12 |
Correct |
9 ms |
1504 KB |
Output is correct |
13 |
Correct |
9 ms |
1772 KB |
Output is correct |
14 |
Correct |
9 ms |
1624 KB |
Output is correct |
15 |
Correct |
30 ms |
3388 KB |
Output is correct |
16 |
Correct |
27 ms |
3000 KB |
Output is correct |
17 |
Correct |
25 ms |
3072 KB |
Output is correct |
18 |
Correct |
28 ms |
2896 KB |
Output is correct |
19 |
Correct |
26 ms |
3144 KB |
Output is correct |
20 |
Correct |
28 ms |
3108 KB |
Output is correct |
21 |
Correct |
34 ms |
3384 KB |
Output is correct |
22 |
Correct |
27 ms |
3028 KB |
Output is correct |
23 |
Correct |
28 ms |
3224 KB |
Output is correct |
24 |
Correct |
29 ms |
3140 KB |
Output is correct |
25 |
Correct |
28 ms |
3132 KB |
Output is correct |
26 |
Correct |
29 ms |
2972 KB |
Output is correct |
27 |
Correct |
36 ms |
3148 KB |
Output is correct |
28 |
Correct |
28 ms |
3216 KB |
Output is correct |
29 |
Correct |
28 ms |
3260 KB |
Output is correct |
30 |
Correct |
28 ms |
3252 KB |
Output is correct |
31 |
Correct |
30 ms |
3268 KB |
Output is correct |
32 |
Correct |
31 ms |
3376 KB |
Output is correct |
33 |
Correct |
28 ms |
3492 KB |
Output is correct |
34 |
Correct |
28 ms |
3104 KB |
Output is correct |
35 |
Incorrect |
29 ms |
3168 KB |
Wrong Answer [2] |
36 |
Halted |
0 ms |
0 KB |
- |