#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define endl '\n'
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int CURR=0;
int same(int x){
int temp=Query(x);
int res=CURR==temp;
CURR=temp;
return res;
}
int n;
int in[50005];
int mask[50005];
vector<ii> v;
int pos[70005];
vector<int> posi[70005];
vector<int> posi2[70005];
int done[70005];
void solve(vector<int> l,vector<int> r,int TOGGLE){
int n=sz(l);
v.clear();
rep(x,0,70005) posi[x].clear();
rep(x,0,70005) posi2[x].clear();
memset(done,-1,sizeof(done));
rep(x,0,n) in[x]=TOGGLE;
rep(x,0,n) mask[x]=0;
//for (auto it:l) cout<<it<<" "; cout<<endl;
//for (auto it:r) cout<<it<<" "; cout<<endl;
//cout<<TOGGLE<<endl<<endl;
int s=0;
while ((1<<s)<n) s++;
rep(x,0,1<<s){
int curr=0;
int num=0;
rep(bit,0,s){
int temp=!!(x&(1<<bit));
if (curr!=temp) num++;
curr=temp;
}
v.pub({num,x});
}
sort(all(v));
if (TOGGLE==1) for (auto &it:v) it.se^=(1<<s)-1;
rep(x,0,sz(v)) pos[v[x].se]=x;
int af=(1<<(s-1))-1;
rep(x,0,n) posi[v[x].se&af].pub(v[x].se);
rep(x,0,n) posi2[v[x].se&(af>>1)].pub(v[x].se);
rep(bit,0,s){
rep(x,0,n){
int val=!!(v[x].se&(1<<bit));
if (in[x]!=val) same(l[x]);
in[x]=val;
}
rep(x,0,n){
if (bit==s-1){
if (sz(posi[mask[x]])==1){
mask[x]=posi[mask[x]][0];
}
else if (done[mask[x]]==-1){
if (same(r[x])){
done[mask[x]]=0;
mask[x]|=1<<bit;
}
else{
done[mask[x]]=1;
}
}
else{
mask[x]|=done[mask[x]]<<bit;
}
}
else{
if (same(r[x])) mask[x]|=1<<bit;
}
}
}
rep(x,0,n) Answer(l[pos[mask[x]]],r[x]);
}
void Solve(signed N) {
n=N;
vector<int> idx;
rep(x,1,2*n+1) idx.pub(x);
shuffle(all(idx),rng);
vector<int> l1,r1;
vector<int> l2,r2;
vector<int> l3,r3;
rep(x,0,n){
if (same(idx[x])) r1.pub(idx[x]);
else l1.pub(idx[x]);
}
vector<int> temp;
for (auto it:l1){
if (same(it)) temp.pub(it);
else l2.pub(it);
}
solve(r1,temp,1);
rep(x,n,2*n){
if (same(idx[x])) r3.pub(idx[x]);
else l3.pub(idx[x]);
}
temp.clear();
for (auto it:l3){
if (same(it)) temp.pub(it);
else r2.pub(it);
}
solve(r3,temp,1);
solve(l2,r2,0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4120 KB |
Output is correct |
2 |
Correct |
2 ms |
4176 KB |
Output is correct |
3 |
Correct |
3 ms |
4176 KB |
Output is correct |
4 |
Correct |
3 ms |
4176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4176 KB |
Output is correct |
2 |
Correct |
4 ms |
4396 KB |
Output is correct |
3 |
Correct |
6 ms |
4560 KB |
Output is correct |
4 |
Correct |
9 ms |
5072 KB |
Output is correct |
5 |
Correct |
15 ms |
5836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4120 KB |
Output is correct |
2 |
Correct |
2 ms |
4176 KB |
Output is correct |
3 |
Correct |
3 ms |
4176 KB |
Output is correct |
4 |
Correct |
3 ms |
4176 KB |
Output is correct |
5 |
Correct |
3 ms |
4176 KB |
Output is correct |
6 |
Correct |
4 ms |
4396 KB |
Output is correct |
7 |
Correct |
6 ms |
4560 KB |
Output is correct |
8 |
Correct |
9 ms |
5072 KB |
Output is correct |
9 |
Correct |
15 ms |
5836 KB |
Output is correct |
10 |
Correct |
4 ms |
4176 KB |
Output is correct |
11 |
Correct |
14 ms |
5452 KB |
Output is correct |
12 |
Correct |
17 ms |
5836 KB |
Output is correct |
13 |
Correct |
17 ms |
5908 KB |
Output is correct |
14 |
Correct |
16 ms |
5836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4120 KB |
Output is correct |
2 |
Correct |
2 ms |
4176 KB |
Output is correct |
3 |
Correct |
3 ms |
4176 KB |
Output is correct |
4 |
Correct |
3 ms |
4176 KB |
Output is correct |
5 |
Correct |
3 ms |
4176 KB |
Output is correct |
6 |
Correct |
4 ms |
4396 KB |
Output is correct |
7 |
Correct |
6 ms |
4560 KB |
Output is correct |
8 |
Correct |
9 ms |
5072 KB |
Output is correct |
9 |
Correct |
15 ms |
5836 KB |
Output is correct |
10 |
Correct |
4 ms |
4176 KB |
Output is correct |
11 |
Correct |
14 ms |
5452 KB |
Output is correct |
12 |
Correct |
17 ms |
5836 KB |
Output is correct |
13 |
Correct |
17 ms |
5908 KB |
Output is correct |
14 |
Correct |
16 ms |
5836 KB |
Output is correct |
15 |
Correct |
51 ms |
9268 KB |
Output is correct |
16 |
Correct |
44 ms |
9204 KB |
Output is correct |
17 |
Correct |
50 ms |
9220 KB |
Output is correct |
18 |
Correct |
43 ms |
9048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4120 KB |
Output is correct |
2 |
Correct |
2 ms |
4176 KB |
Output is correct |
3 |
Correct |
3 ms |
4176 KB |
Output is correct |
4 |
Correct |
3 ms |
4176 KB |
Output is correct |
5 |
Correct |
3 ms |
4176 KB |
Output is correct |
6 |
Correct |
4 ms |
4396 KB |
Output is correct |
7 |
Correct |
6 ms |
4560 KB |
Output is correct |
8 |
Correct |
9 ms |
5072 KB |
Output is correct |
9 |
Correct |
15 ms |
5836 KB |
Output is correct |
10 |
Correct |
4 ms |
4176 KB |
Output is correct |
11 |
Correct |
14 ms |
5452 KB |
Output is correct |
12 |
Correct |
17 ms |
5836 KB |
Output is correct |
13 |
Correct |
17 ms |
5908 KB |
Output is correct |
14 |
Correct |
16 ms |
5836 KB |
Output is correct |
15 |
Correct |
51 ms |
9268 KB |
Output is correct |
16 |
Correct |
44 ms |
9204 KB |
Output is correct |
17 |
Correct |
50 ms |
9220 KB |
Output is correct |
18 |
Correct |
43 ms |
9048 KB |
Output is correct |
19 |
Correct |
63 ms |
9296 KB |
Output is correct |
20 |
Correct |
58 ms |
9272 KB |
Output is correct |
21 |
Correct |
48 ms |
9276 KB |
Output is correct |
22 |
Correct |
54 ms |
9100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4120 KB |
Output is correct |
2 |
Correct |
2 ms |
4176 KB |
Output is correct |
3 |
Correct |
3 ms |
4176 KB |
Output is correct |
4 |
Correct |
3 ms |
4176 KB |
Output is correct |
5 |
Correct |
3 ms |
4176 KB |
Output is correct |
6 |
Correct |
4 ms |
4396 KB |
Output is correct |
7 |
Correct |
6 ms |
4560 KB |
Output is correct |
8 |
Correct |
9 ms |
5072 KB |
Output is correct |
9 |
Correct |
15 ms |
5836 KB |
Output is correct |
10 |
Correct |
4 ms |
4176 KB |
Output is correct |
11 |
Correct |
14 ms |
5452 KB |
Output is correct |
12 |
Correct |
17 ms |
5836 KB |
Output is correct |
13 |
Correct |
17 ms |
5908 KB |
Output is correct |
14 |
Correct |
16 ms |
5836 KB |
Output is correct |
15 |
Correct |
51 ms |
9268 KB |
Output is correct |
16 |
Correct |
44 ms |
9204 KB |
Output is correct |
17 |
Correct |
50 ms |
9220 KB |
Output is correct |
18 |
Correct |
43 ms |
9048 KB |
Output is correct |
19 |
Correct |
63 ms |
9296 KB |
Output is correct |
20 |
Correct |
58 ms |
9272 KB |
Output is correct |
21 |
Correct |
48 ms |
9276 KB |
Output is correct |
22 |
Correct |
54 ms |
9100 KB |
Output is correct |
23 |
Correct |
52 ms |
9408 KB |
Output is correct |
24 |
Correct |
61 ms |
9448 KB |
Output is correct |
25 |
Correct |
46 ms |
9376 KB |
Output is correct |
26 |
Correct |
53 ms |
9228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4120 KB |
Output is correct |
2 |
Correct |
2 ms |
4176 KB |
Output is correct |
3 |
Correct |
3 ms |
4176 KB |
Output is correct |
4 |
Correct |
3 ms |
4176 KB |
Output is correct |
5 |
Correct |
3 ms |
4176 KB |
Output is correct |
6 |
Correct |
4 ms |
4396 KB |
Output is correct |
7 |
Correct |
6 ms |
4560 KB |
Output is correct |
8 |
Correct |
9 ms |
5072 KB |
Output is correct |
9 |
Correct |
15 ms |
5836 KB |
Output is correct |
10 |
Correct |
4 ms |
4176 KB |
Output is correct |
11 |
Correct |
14 ms |
5452 KB |
Output is correct |
12 |
Correct |
17 ms |
5836 KB |
Output is correct |
13 |
Correct |
17 ms |
5908 KB |
Output is correct |
14 |
Correct |
16 ms |
5836 KB |
Output is correct |
15 |
Correct |
51 ms |
9268 KB |
Output is correct |
16 |
Correct |
44 ms |
9204 KB |
Output is correct |
17 |
Correct |
50 ms |
9220 KB |
Output is correct |
18 |
Correct |
43 ms |
9048 KB |
Output is correct |
19 |
Correct |
63 ms |
9296 KB |
Output is correct |
20 |
Correct |
58 ms |
9272 KB |
Output is correct |
21 |
Correct |
48 ms |
9276 KB |
Output is correct |
22 |
Correct |
54 ms |
9100 KB |
Output is correct |
23 |
Correct |
52 ms |
9408 KB |
Output is correct |
24 |
Correct |
61 ms |
9448 KB |
Output is correct |
25 |
Correct |
46 ms |
9376 KB |
Output is correct |
26 |
Correct |
53 ms |
9228 KB |
Output is correct |
27 |
Correct |
48 ms |
9676 KB |
Output is correct |
28 |
Correct |
48 ms |
9492 KB |
Output is correct |
29 |
Correct |
45 ms |
9448 KB |
Output is correct |
30 |
Correct |
47 ms |
9416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4120 KB |
Output is correct |
2 |
Correct |
2 ms |
4176 KB |
Output is correct |
3 |
Correct |
3 ms |
4176 KB |
Output is correct |
4 |
Correct |
3 ms |
4176 KB |
Output is correct |
5 |
Correct |
3 ms |
4176 KB |
Output is correct |
6 |
Correct |
4 ms |
4396 KB |
Output is correct |
7 |
Correct |
6 ms |
4560 KB |
Output is correct |
8 |
Correct |
9 ms |
5072 KB |
Output is correct |
9 |
Correct |
15 ms |
5836 KB |
Output is correct |
10 |
Correct |
4 ms |
4176 KB |
Output is correct |
11 |
Correct |
14 ms |
5452 KB |
Output is correct |
12 |
Correct |
17 ms |
5836 KB |
Output is correct |
13 |
Correct |
17 ms |
5908 KB |
Output is correct |
14 |
Correct |
16 ms |
5836 KB |
Output is correct |
15 |
Correct |
51 ms |
9268 KB |
Output is correct |
16 |
Correct |
44 ms |
9204 KB |
Output is correct |
17 |
Correct |
50 ms |
9220 KB |
Output is correct |
18 |
Correct |
43 ms |
9048 KB |
Output is correct |
19 |
Correct |
63 ms |
9296 KB |
Output is correct |
20 |
Correct |
58 ms |
9272 KB |
Output is correct |
21 |
Correct |
48 ms |
9276 KB |
Output is correct |
22 |
Correct |
54 ms |
9100 KB |
Output is correct |
23 |
Correct |
52 ms |
9408 KB |
Output is correct |
24 |
Correct |
61 ms |
9448 KB |
Output is correct |
25 |
Correct |
46 ms |
9376 KB |
Output is correct |
26 |
Correct |
53 ms |
9228 KB |
Output is correct |
27 |
Correct |
48 ms |
9676 KB |
Output is correct |
28 |
Correct |
48 ms |
9492 KB |
Output is correct |
29 |
Correct |
45 ms |
9448 KB |
Output is correct |
30 |
Correct |
47 ms |
9416 KB |
Output is correct |
31 |
Correct |
60 ms |
9544 KB |
Output is correct |
32 |
Correct |
65 ms |
9592 KB |
Output is correct |
33 |
Correct |
58 ms |
9632 KB |
Output is correct |
34 |
Correct |
47 ms |
9404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4120 KB |
Output is correct |
2 |
Correct |
2 ms |
4176 KB |
Output is correct |
3 |
Correct |
3 ms |
4176 KB |
Output is correct |
4 |
Correct |
3 ms |
4176 KB |
Output is correct |
5 |
Correct |
3 ms |
4176 KB |
Output is correct |
6 |
Correct |
4 ms |
4396 KB |
Output is correct |
7 |
Correct |
6 ms |
4560 KB |
Output is correct |
8 |
Correct |
9 ms |
5072 KB |
Output is correct |
9 |
Correct |
15 ms |
5836 KB |
Output is correct |
10 |
Correct |
4 ms |
4176 KB |
Output is correct |
11 |
Correct |
14 ms |
5452 KB |
Output is correct |
12 |
Correct |
17 ms |
5836 KB |
Output is correct |
13 |
Correct |
17 ms |
5908 KB |
Output is correct |
14 |
Correct |
16 ms |
5836 KB |
Output is correct |
15 |
Correct |
51 ms |
9268 KB |
Output is correct |
16 |
Correct |
44 ms |
9204 KB |
Output is correct |
17 |
Correct |
50 ms |
9220 KB |
Output is correct |
18 |
Correct |
43 ms |
9048 KB |
Output is correct |
19 |
Correct |
63 ms |
9296 KB |
Output is correct |
20 |
Correct |
58 ms |
9272 KB |
Output is correct |
21 |
Correct |
48 ms |
9276 KB |
Output is correct |
22 |
Correct |
54 ms |
9100 KB |
Output is correct |
23 |
Correct |
52 ms |
9408 KB |
Output is correct |
24 |
Correct |
61 ms |
9448 KB |
Output is correct |
25 |
Correct |
46 ms |
9376 KB |
Output is correct |
26 |
Correct |
53 ms |
9228 KB |
Output is correct |
27 |
Correct |
48 ms |
9676 KB |
Output is correct |
28 |
Correct |
48 ms |
9492 KB |
Output is correct |
29 |
Correct |
45 ms |
9448 KB |
Output is correct |
30 |
Correct |
47 ms |
9416 KB |
Output is correct |
31 |
Correct |
60 ms |
9544 KB |
Output is correct |
32 |
Correct |
65 ms |
9592 KB |
Output is correct |
33 |
Correct |
58 ms |
9632 KB |
Output is correct |
34 |
Correct |
47 ms |
9404 KB |
Output is correct |
35 |
Incorrect |
51 ms |
9752 KB |
Wrong Answer [2] |
36 |
Halted |
0 ms |
0 KB |
- |