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 "minerals.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=5e4+7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
vector<int>T, zapalone;
int czy[LIM], lst=-1;
bool pytaj(int x) {
int a=Query(x+1);
swap(a, lst);
return a!=lst;
}
void dc(int l, int r, vector<pair<int,int>>&V) {
if(l==r) {
Answer(T[l]+1, V[0].st+1);
return;
}
int mid=(l+r)/2;
vector<int>tmp;
for(auto i : zapalone) {
if(i<l || i>mid) {
pytaj(T[i]);
czy[i]=0;
} else tmp.pb(i);
}
zapalone=tmp;
for(int i=l; i<=mid; ++i) if(!czy[i]) {
pytaj(T[i]);
zapalone.pb(i);
czy[i]=1;
}
vector<pair<int,int>>A, B;
for(auto i : V) if(i.nd<=mid || !pytaj(i.st)) A.pb(i); else B.pb(i);
dc(l, mid, A);
dc(mid+1, r, B);
}
void Solve(int n) {
vector<int>P;
rep(i, 2*n) {
P.pb(i);
swap(P[i], P[rng()%(i+1)]);
}
vector<pair<int,int>>V;
rep(i, 2*n) {
if(pytaj(P[i])) T.pb(P[i]);
else V.pb({P[i], (int)T.size()-1});
}
rep(i, T.size()) {
zapalone.pb(i);
czy[i]=1;
}
dc(0, n-1, V);
}
Compilation message (stderr)
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:5:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | #define rep(a, b) for(int a = 0; a < (b); ++a)
| ^
minerals.cpp:54:2: note: in expansion of macro 'rep'
54 | rep(i, T.size()) {
| ^~~
# | 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... |