This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Query(int x);
void Answer(int a, int b);
vector<pii> risposta;
int already;
void dc(vector<int>& a, vector<int>& b){
assert(SZ(a) == SZ(b));
if(SZ(a) == 0) return;
if(SZ(a) == 1){
already += 1;
//Query(a[0]);
risposta.pb({a[0], b[0]});
return;
}
int m = SZ(b) / 2, prev = already + SZ(a);
for(int i = 0; i < m; i++){
Query(b[i]);
}
vector<int> b_left, b_right;
for(int i = 0; i < SZ(a); i++){
int ans = Query(a[i]);
if(ans < prev){
b_right.pb(a[i]);
} else if(ans == prev){
b_left.pb(a[i]);
}
prev = ans;
}
vector<int> a_left, a_right;
for(int i = 0; i < m; i++){
a_left.pb(b[i]);
}
dc(a_left, b_left);
for(int i = m; i < SZ(b); i++){
Query(b[i]);
a_right.pb(b[i]);
}
dc(a_right, b_right);
}
void Solve(int N){
vector<int> a, b;
int prev = 0;
vector<int> v(2 * N);
iota(all(v), 1);
shuffle(all(v), rng);
for(int i = 0; i < 2 * N; i++){
int ans = Query(v[i]);
if(ans == prev){
Query(v[i]);
b.pb(v[i]);
} else if(ans > prev){
a.pb(v[i]);
}
prev = ans;
if(ans == N){
i++;
while(i < 2 * N){
b.pb(v[i++]);
}
break;
}
}
dc(a, b);
for(auto x : risposta){
Answer(x.ff, x.ss);
}
}
# | 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... |