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 "prize.h"
#include "bits/stdc++.h"
using namespace std;
int ddd = 1;
int fen[200005][10];
int corr[10];
int n;
unordered_map<int, int> aaa;
void add(int id, int x, int k) {
id++;
while(id <= n) {
fen[id][k] += x;
id += (id & (-id));
}
}
int sum(int id, int k) {
int ans = 0;
id++;
while(id > 0) {
ans += fen[id][k];
id -= (id & (-id));
}
return ans;
}
int getbefore(int id, int k) {
int t = 0;
for(int i = 1; i < ddd; i++) {
if(corr[i] < k) t += sum(id, i);
}
return t;
}
void add_val(int a, int k) {
if(aaa[k] == 0) {corr[ddd] = k; aaa[k] = ddd++;}
add(a, 1, aaa[k]);
}
bool vi[200005];
vector<int> store[200005];
int now = 0;
int dx = 0;
int sign = 1;
vector<int> aa(int t) {
// cerr << t << '\n';
if(vi[t]) {
int k = 0;
while((t - k < 0 ||vi[t - k]) && (t + k >= n || vi[t + k])) k++;
if(t - k >= 0 && !vi[t - k]) now = t = t - k;
else now = t = t + k;
}
// vi[t] = true;
return store[t] = ask(t);
}
int ans = -1;
int ll = 0;
void solve(int l, int r) {
// cerr << l << ' ' << r << '\n';
if(l > r) return;
int m = (l + r) / 2;
vector<int> res = aa(m);
if(res[0] + res[1] == 0) {ans = m; return;}
if(!vi[m]) add_val(m, res[0] + res[1]);
vi[m] = true;
// if(l == r) {
// ll = m + 1;
// return;
// }
if(res[0] == getbefore(m, res[0] + res[1])) {
ll = m + 1;
solve(m + 1, r);
}
else {
solve(l, m);
}
}
int find_best(int N) {
n = N;
// int t = 100;
while(ans == -1) {
solve(ll, n - 1);
// cerr << now << '\n';
// vector<int> res = aa(now);
// if(res[0] + res[1] == 0) return now;
// if(!vi[now]) add_val(now, res[0] + res[1]);
// vi[now] = true;
// if(res[0] <= getbefore(now, res[0] + res[1])) {
// sign = 1;
// dx *= 2;
// if(dx == 0) dx++;
// }
// else {
// sign = -1;
// dx /= 2;
// if(dx == 0) dx++;
// }
// if(sign == 1) dx = min(dx, n - 1 - now);
// else dx = min(dx, now);
// now += dx * sign;
}
return ans;
// for(int i = 0; i < n; i++) {
// vector<int> res = ask(i);
// if(res[0] + res[1] == 0)
// return i;
// }
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |