#include "minerals.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;
bool is_on[100'000];
int ans[100'001];
int cur_dif;
int ask(int x)
{
is_on[x] ^= 1;
return Query(x);
}
void solve(vi A, vi B)
{
if(siz(A) == 1)
{
ans[A[0]] = B[0];
return;
}
int c0_A = 0;
int c1_A = 0;
forall(it,A)
{
if(is_on[it] == 0) c0_A++;
else c1_A++;
}
int c0_B = 0;
int c1_B = 0;
forall(it,B)
{
if(is_on[it] == 0) c0_B++;
else c1_B++;
}
int v1 = abs(c0_A - siz(A)/2);
int v2 = abs(c0_A - (siz(A)+1)/2);
int v3 = abs(c1_A - siz(A)/2);
int v4 = abs(c1_A - (siz(A)+1)/2);
int v5 = abs(c0_B - siz(B)/2);
int v6 = abs(c0_B - (siz(B)+1)/2);
int v7 = abs(c1_B - siz(B)/2);
int v8 = abs(c1_B - (siz(B)+1)/2);
//cout << v1 << " " << v2 << " " << v3 << " " << v4 << " " << v5 << " " << v6 << " " << v7 << " " << v8 << " v\n";
if(min({v1,v2,v3,v4}) < min({v5,v6,v7,v8}))
{
if(min({v1,v2}) <= min({v3,v4}))
{
if(c0_A >= siz(A)/2)
{
forall(it,A)
{
if(!is_on[it] && c0_A > (siz(A)+1)/2)
{
cur_dif = ask(it);
c0_A--;
}
}
}
else
{
forall(it,A)
{
if(is_on[it] && c0_A < (siz(A))/2)
{
cur_dif = ask(it);
c0_A++;
}
}
}
}
else
{
if(c1_A >= siz(A)/2)
{
forall(it,A)
{
if(is_on[it] && c1_A > (siz(A)+1)/2)
{
cur_dif = ask(it);
c1_A--;
}
}
}
else
{
forall(it,A)
{
if(!is_on[it] && c1_A < (siz(A))/2)
{
cur_dif = ask(it);
c1_A++;
}
}
}
}
swap(A,B);
}
else
{
if(min({v5,v6}) <= min({v7,v8}))
{
if(c0_B >= siz(B)/2)
{
forall(it,B)
{
if(!is_on[it] && c0_B > (siz(B)+1)/2)
{
cur_dif = ask(it);
c0_B--;
}
}
}
else
{
forall(it,B)
{
if(is_on[it] && c0_B < (siz(B))/2)
{
cur_dif = ask(it);
c0_B++;
}
}
}
}
else
{
if(c1_B >= siz(B)/2)
{
forall(it,B)
{
if(is_on[it] && c1_B > (siz(B)+1)/2)
{
cur_dif = ask(it);
c1_B--;
}
}
}
else
{
forall(it,B)
{
if(!is_on[it] && c1_B < (siz(B))/2)
{
cur_dif = ask(it);
c1_B++;
}
}
}
}
}
vi newA0;
vi newA1;
vi newB0;
vi newB1;
forall(it,B)
{
if(is_on[it]) newB1.pb(it);
else newB0.pb(it);
}
forall(it,A)
{
if(siz(newA0) == siz(newB0))
{
newA1.pb(it);
continue;
}
if(siz(newA1) == siz(newB1))
{
newA0.pb(it);
continue;
}
int new_dif = ask(it);
if(cur_dif != new_dif)
{
newA0.pb(it);
}
else
{
newA1.pb(it);
}
cur_dif = new_dif;
}
solve(newA0,newB0);
solve(newA1,newB1);
}
void Solve(int n)
{
vi A;
vi B;
cur_dif = 0;
rep2(i,1,n*2)
{
int new_dif = ask(i);
if(cur_dif != new_dif)
{
A.pb(i);
}
else
{
B.pb(i);
}
cur_dif = new_dif;
}
solve(A,B);
rep2(i,1,n*2)
{
if(ans[i] != 0)
{
Answer(i,ans[i]);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |