#include <bits/stdc++.h>
#define rep(a,b,c) for(auto a = (b); a != (c); a++)
#define repD(a,b,c) for(auto a = (b); a != (c); a--)
#define repIn(a, b) for(auto& a : (b))
#define repIn2(a, b, c) for(auto& [a, b] : (c))
constexpr bool dbg = 0;
#define DEBUG if constexpr(dbg)
#define DC DEBUG std::cerr
#define eol std::endl
#define ll long long
#define pb push_back
using namespace std;
#include "minerals.h"
constexpr int maxn = 43007 * 2;
bool isIn[maxn];
int cntIn;
int n;
int myQuery(int i) {
if(isIn[i]) cntIn--;
else cntIn++;
isIn[i] = !isIn[i];
int ret = cntIn - Query(i + 1);
DC << " ============ Querying " << i << " -> " << ret << eol;
return ret;
}
int curPairs;
void dq(vector<int> h1, vector<int> h2, bool in1) {
assert(h1.size() == h2.size());
DEBUG {
DC << "D&Q\n h1: {";
repIn(i, h1) DC << i << ", ";
DC << "}\n h2: {";
repIn(i, h2) DC << i << ", ";
DC << "}\n in1 " << in1 << " ; in2 " << eol;
repIn(i, h1) assert(isIn[i] == in1);
//repIn(i, h2) assert(isIn[i] == in2);
}
int sz = (int)h1.size(), m = sz / 2;
if(sz == 1) { Answer(h1.back() + 1, h2.back() + 1); return; }
if(in1) rep(i, m, sz) curPairs = myQuery(h1[i]);
if(!in1) rep(i, 0, m) curPairs = myQuery(h1[i]);
vector<int> lh1, lh2, rh1, rh2;
rep(i, 0, m) lh1.pb(h1[i]);
rep(i, m, sz) rh1.pb(h1[i]);
repIn(i, h2) {
if(lh2.size() == lh1.size()) { rh2.pb(i); continue; }
if(rh2.size() == rh1.size()) { lh2.pb(i); continue; }
auto newPairs = myQuery(i);
if(newPairs != curPairs) lh2.pb(i);
else rh2.pb(i);
curPairs = newPairs;
}
dq(lh1, lh2, true);
dq(rh1, rh2, false);
}
void Solve(int N) {
n = N;
vector<int> firstHalf, secondHalf;
rep(i, 0, 2 * N) {
if((int)firstHalf.size() == n) { secondHalf.pb(i); continue; }
if((int)secondHalf.size() == n) { firstHalf.pb(i), curPairs = myQuery(i); continue; }
auto newPairs = myQuery(i);
if(newPairs != curPairs) secondHalf.pb(i);
else firstHalf.pb(i);
curPairs = newPairs;
}
dq(firstHalf, secondHalf, 1);
}
# | 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... |