#include "minerals.h"
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ii pair<int,int>
#define ll long long
#define orta ((bas+son)>>1)
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define umin(x,y) x=min(x,y)
#define umax(x,y) x=max(x,y)
#define inf 2000000000000000
#define N 500005
#define MOD 998244353
#define KOK 700
using namespace std;
vector<int> A,B;
vector<int> p;
vector<int> on;
int cnt;
mt19937 rnd;
int get(int l,int mid,int r,int ss) {
int tot=0;
for(int i=l;i<=mid;i++) {
if(!(on[i]^ss)) tot++;
}
for(int i=mid+1;i<=r;i++) {
if((on[i]^ss)) tot++;
}
return tot;
}
void make(int l,int mid,int r,int ss) {
for(int i=l;i<=mid;i++) {
if(!(on[i]^ss)) cnt=Query(p[A[i]]),on[i]=!on[i];
}
for(int i=mid+1;i<=r;i++) {
if((on[i]^ss)) cnt=Query(p[A[i]]),on[i]=!on[i];
}
}
void solve(int l,int r,vector<int> cd) {
if(l==r) {
for(auto x:cd) Answer(p[x],p[A[l]]);
return ;
}
int mid=(l+r)>>1;
int sw=0;
int sz[2]={mid-l+1,r-mid};
int tot[2]={0,0};
tot[0]=get(l,mid,r,0);
tot[1]=get(l,mid,r,1);
if(tot[1]<tot[0]) {
make(l,mid,r,1);
sw=1;
swap(sz[0],sz[1]);
} else make(l,mid,r,0);
vector<int> go[2];
bool to[2]={0,0};
shuffle(cd.begin(),cd.end(),rnd);
for(auto x:cd) {
if(to[0]) {go[0].pb(x);continue ;}
if(to[1]) {go[1].pb(x);continue ;}
int cur=Query(p[x]);
if(cnt!=cur) {
go[1].pb(x);
}
else {
go[0].pb(x);
}
cnt=cur;
if(sz(go[0])==sz[0]) to[1]=1;
if(sz(go[1])==sz[1]) to[0]=1;
}
if(sw) swap(go[0],go[1]);
solve(l,mid,go[0]);
solve(mid+1,r,go[1]);
}
void Solve(int n) {
n<<=1;
rnd=mt19937(time(NULL));
on=vector<int>(n,0);
for(int i=1;i<=n;i++) p.pb(i);
shuffle(p.begin(),p.end(),rnd);
bool toA=0,toB=0;
for(int i=0;i<n;i++) {
if(toA) {A.pb(i);continue ;}
if(toB) {B.pb(i);continue ;}
int cur=Query(p[i]);
on[i]=!on[i];
if(cur>cnt) {
A.pb(i);
}
else {
B.pb(i);
}
if(sz(A)==n/2) toB=1;
if(sz(B)==n/2) toA=1;
cnt=cur;
}
solve(0,sz(A)-1,B);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
8 ms |
504 KB |
Output is correct |
4 |
Correct |
15 ms |
760 KB |
Output is correct |
5 |
Correct |
29 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
8 ms |
504 KB |
Output is correct |
8 |
Correct |
15 ms |
760 KB |
Output is correct |
9 |
Correct |
29 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
21 ms |
1144 KB |
Output is correct |
12 |
Correct |
30 ms |
1400 KB |
Output is correct |
13 |
Correct |
30 ms |
1400 KB |
Output is correct |
14 |
Correct |
29 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
8 ms |
504 KB |
Output is correct |
8 |
Correct |
15 ms |
760 KB |
Output is correct |
9 |
Correct |
29 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
21 ms |
1144 KB |
Output is correct |
12 |
Correct |
30 ms |
1400 KB |
Output is correct |
13 |
Correct |
30 ms |
1400 KB |
Output is correct |
14 |
Correct |
29 ms |
1272 KB |
Output is correct |
15 |
Correct |
98 ms |
3104 KB |
Output is correct |
16 |
Correct |
88 ms |
3056 KB |
Output is correct |
17 |
Correct |
86 ms |
3128 KB |
Output is correct |
18 |
Correct |
87 ms |
3068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
8 ms |
504 KB |
Output is correct |
8 |
Correct |
15 ms |
760 KB |
Output is correct |
9 |
Correct |
29 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
21 ms |
1144 KB |
Output is correct |
12 |
Correct |
30 ms |
1400 KB |
Output is correct |
13 |
Correct |
30 ms |
1400 KB |
Output is correct |
14 |
Correct |
29 ms |
1272 KB |
Output is correct |
15 |
Correct |
98 ms |
3104 KB |
Output is correct |
16 |
Correct |
88 ms |
3056 KB |
Output is correct |
17 |
Correct |
86 ms |
3128 KB |
Output is correct |
18 |
Correct |
87 ms |
3068 KB |
Output is correct |
19 |
Correct |
91 ms |
3188 KB |
Output is correct |
20 |
Correct |
88 ms |
3052 KB |
Output is correct |
21 |
Correct |
91 ms |
3104 KB |
Output is correct |
22 |
Correct |
90 ms |
3044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
8 ms |
504 KB |
Output is correct |
8 |
Correct |
15 ms |
760 KB |
Output is correct |
9 |
Correct |
29 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
21 ms |
1144 KB |
Output is correct |
12 |
Correct |
30 ms |
1400 KB |
Output is correct |
13 |
Correct |
30 ms |
1400 KB |
Output is correct |
14 |
Correct |
29 ms |
1272 KB |
Output is correct |
15 |
Correct |
98 ms |
3104 KB |
Output is correct |
16 |
Correct |
88 ms |
3056 KB |
Output is correct |
17 |
Correct |
86 ms |
3128 KB |
Output is correct |
18 |
Correct |
87 ms |
3068 KB |
Output is correct |
19 |
Correct |
91 ms |
3188 KB |
Output is correct |
20 |
Correct |
88 ms |
3052 KB |
Output is correct |
21 |
Correct |
91 ms |
3104 KB |
Output is correct |
22 |
Correct |
90 ms |
3044 KB |
Output is correct |
23 |
Correct |
92 ms |
3260 KB |
Output is correct |
24 |
Correct |
94 ms |
3184 KB |
Output is correct |
25 |
Correct |
89 ms |
3184 KB |
Output is correct |
26 |
Correct |
90 ms |
3056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
8 ms |
504 KB |
Output is correct |
8 |
Correct |
15 ms |
760 KB |
Output is correct |
9 |
Correct |
29 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
21 ms |
1144 KB |
Output is correct |
12 |
Correct |
30 ms |
1400 KB |
Output is correct |
13 |
Correct |
30 ms |
1400 KB |
Output is correct |
14 |
Correct |
29 ms |
1272 KB |
Output is correct |
15 |
Correct |
98 ms |
3104 KB |
Output is correct |
16 |
Correct |
88 ms |
3056 KB |
Output is correct |
17 |
Correct |
86 ms |
3128 KB |
Output is correct |
18 |
Correct |
87 ms |
3068 KB |
Output is correct |
19 |
Correct |
91 ms |
3188 KB |
Output is correct |
20 |
Correct |
88 ms |
3052 KB |
Output is correct |
21 |
Correct |
91 ms |
3104 KB |
Output is correct |
22 |
Correct |
90 ms |
3044 KB |
Output is correct |
23 |
Correct |
92 ms |
3260 KB |
Output is correct |
24 |
Correct |
94 ms |
3184 KB |
Output is correct |
25 |
Correct |
89 ms |
3184 KB |
Output is correct |
26 |
Correct |
90 ms |
3056 KB |
Output is correct |
27 |
Correct |
95 ms |
3312 KB |
Output is correct |
28 |
Correct |
95 ms |
3232 KB |
Output is correct |
29 |
Correct |
92 ms |
3356 KB |
Output is correct |
30 |
Correct |
93 ms |
3140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
8 ms |
504 KB |
Output is correct |
8 |
Correct |
15 ms |
760 KB |
Output is correct |
9 |
Correct |
29 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
21 ms |
1144 KB |
Output is correct |
12 |
Correct |
30 ms |
1400 KB |
Output is correct |
13 |
Correct |
30 ms |
1400 KB |
Output is correct |
14 |
Correct |
29 ms |
1272 KB |
Output is correct |
15 |
Correct |
98 ms |
3104 KB |
Output is correct |
16 |
Correct |
88 ms |
3056 KB |
Output is correct |
17 |
Correct |
86 ms |
3128 KB |
Output is correct |
18 |
Correct |
87 ms |
3068 KB |
Output is correct |
19 |
Correct |
91 ms |
3188 KB |
Output is correct |
20 |
Correct |
88 ms |
3052 KB |
Output is correct |
21 |
Correct |
91 ms |
3104 KB |
Output is correct |
22 |
Correct |
90 ms |
3044 KB |
Output is correct |
23 |
Correct |
92 ms |
3260 KB |
Output is correct |
24 |
Correct |
94 ms |
3184 KB |
Output is correct |
25 |
Correct |
89 ms |
3184 KB |
Output is correct |
26 |
Correct |
90 ms |
3056 KB |
Output is correct |
27 |
Correct |
95 ms |
3312 KB |
Output is correct |
28 |
Correct |
95 ms |
3232 KB |
Output is correct |
29 |
Correct |
92 ms |
3356 KB |
Output is correct |
30 |
Correct |
93 ms |
3140 KB |
Output is correct |
31 |
Correct |
96 ms |
3408 KB |
Output is correct |
32 |
Correct |
108 ms |
3440 KB |
Output is correct |
33 |
Correct |
93 ms |
3440 KB |
Output is correct |
34 |
Correct |
94 ms |
3104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
8 ms |
504 KB |
Output is correct |
8 |
Correct |
15 ms |
760 KB |
Output is correct |
9 |
Correct |
29 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
21 ms |
1144 KB |
Output is correct |
12 |
Correct |
30 ms |
1400 KB |
Output is correct |
13 |
Correct |
30 ms |
1400 KB |
Output is correct |
14 |
Correct |
29 ms |
1272 KB |
Output is correct |
15 |
Correct |
98 ms |
3104 KB |
Output is correct |
16 |
Correct |
88 ms |
3056 KB |
Output is correct |
17 |
Correct |
86 ms |
3128 KB |
Output is correct |
18 |
Correct |
87 ms |
3068 KB |
Output is correct |
19 |
Correct |
91 ms |
3188 KB |
Output is correct |
20 |
Correct |
88 ms |
3052 KB |
Output is correct |
21 |
Correct |
91 ms |
3104 KB |
Output is correct |
22 |
Correct |
90 ms |
3044 KB |
Output is correct |
23 |
Correct |
92 ms |
3260 KB |
Output is correct |
24 |
Correct |
94 ms |
3184 KB |
Output is correct |
25 |
Correct |
89 ms |
3184 KB |
Output is correct |
26 |
Correct |
90 ms |
3056 KB |
Output is correct |
27 |
Correct |
95 ms |
3312 KB |
Output is correct |
28 |
Correct |
95 ms |
3232 KB |
Output is correct |
29 |
Correct |
92 ms |
3356 KB |
Output is correct |
30 |
Correct |
93 ms |
3140 KB |
Output is correct |
31 |
Correct |
96 ms |
3408 KB |
Output is correct |
32 |
Correct |
108 ms |
3440 KB |
Output is correct |
33 |
Correct |
93 ms |
3440 KB |
Output is correct |
34 |
Correct |
94 ms |
3104 KB |
Output is correct |
35 |
Incorrect |
97 ms |
3392 KB |
Wrong Answer [2] |
36 |
Halted |
0 ms |
0 KB |
- |