이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "prize.h"
#include<bits/stdc++.h>
using namespace std;
mt19937 rng(time(nullptr));
const int N=2e5+5;
struct fenwick{
int t[N];
void add(int i,int v){
i++;
while(i<N)t[i]+=v,i+=i&-i;
}
int read(int i){
i++;
int res=0;
while(i>0)res+=t[i],i-=i&-i;
return res;
}
}f;
int cnt=0;
int n;
int ans=-1;
vector<vector<int>> mem(N);
int mx;
vector<int> vec;
vector<int> ask2(int x){
if(mem[x].empty()){
assert(++cnt<=1e4);
mem[x]=ask(x);
}
return mem[x];
}
int bsearch(){
int l=0,r=vec.size()-1;
while(l<r){
int mid=(l+r)/2;
int m=vec[mid];
auto res=ask2(m);
int val=res[0]+res[1];
if(val<mx)return m;
if(res[0]-f.read(m-1)){
r=mid-1;
}else{
l=mid+1;
}
}
return vec[l];
}
int find_best(int _n) {
n=_n;
for(int i=0;i<n;i++)vec.emplace_back(i);
for(int i=0;i*i<n;i++){
auto res=ask2(i);
mx=max(mx,res[0]+res[1]);
}
for(int i=0;i*i<n;i++){
auto res=ask2(i);
if(res[0]+res[1]==mx)continue;
if(res[0]+res[1]==0)return i;
f.add(i,1);
vec.erase(lower_bound(vec.begin(),vec.end(),i));
}
while(ans==-1){
int x=bsearch();
auto res=ask2(x);
if(res[0]+res[1]==0)return x;
f.add(x,1);
vec.erase(lower_bound(vec.begin(),vec.end(),x));
}
return ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |