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;
#define ll long long
#define pii pair<int, int>
const int MAX = 2e5 + 5, BLOCK = 500;
int tree[MAX];
vector<int> H[MAX];
int det = 0;
void update(int pos, int val){
for(int i = pos; i < MAX; i += (-i & i)){
tree[i] += val;
}
}
int q(int l, int r){
if(l != 1) return q(1, r) - q(1, l - 1);
int res = 0;
for(int i = r; i > 0; i -= (-i & i)){
res += tree[i];
}
return res;
}
int find_best(int n){
for(int i = 0; i < min(BLOCK, n); i++){
H[i] = ask(i);
if(H[i][0] + H[i][1] == 0) return i;
det = max(det, H[i][0] + H[i][1]);
}
set<int> s;
for(int i = 0; i < n; i++){
s.insert(i);
}
for(int k = 1; k <= det; k++){
int l = 0, r = n - 1;
while(l <= r){
int mid = (l + r) / 2;
auto itr = s.lower_bound(mid);
if(itr == s.end()) --itr;
mid = *itr;
if(H[mid].empty()){
H[mid] = ask(mid);
}
if(H[mid][0] + H[mid][1] == 0) return mid;
if(H[mid][0] + H[mid][1] != det){
update(mid + 1, 1);
s.erase(mid);
break;
}
if(H[mid][1] - q(mid + 2, n)){
l = mid + 1;
}
else{
r = mid - 1;
}
}
}
}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:36:14: warning: control reaches end of non-void function [-Wreturn-type]
36 | set<int> s;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |