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 <vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
#define MX 202300
int n,m,l,r,mx,mid,x,p[MX];
vector<int>s;
struct Tree
{
int c[MX];
void add(int x)
{
x++;
for(;x<=n;x+=x&-x)
c[x]++;
return;
}
int ask(int x)
{
x++;
int sum=0;
for(;x;x-=x&-x)
sum+=c[x];
return sum;
}
}T;
int find(int x)
{
int now=0;
if(!p[now])x--;
while(x){
now++;
while(p[now])now++;
x--;
}
return now;
}
int find_best(int N) {
n=N;
mx=0;
for(int i=0;i<min(500,n);++i){
s=ask(i);
mx=max(mx,s[0]+s[1]);
}
for(int i=0;i<n;++i)
p[i]=0;
m=n;
while(1){
l=1;r=m;
while(l<r){
mid=l+r>>1;
x=find(mid);
s=ask(x);
if(s[0]+s[1]!=mx){
l=mid;
break;
}
if(s[0]>T.ask(x))r=mid-1;
else l=mid+1;
}
x=find(l);
if(s[0]+s[1]==0)return x;
p[x]=1;
T.add(x);
}
}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:63:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
63 | mid=l+r>>1;
| ~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |