Submission #797309

#TimeUsernameProblemLanguageResultExecution timeMemory
797309firewaterThe Big Prize (IOI17_prize)C++14
0 / 100
3083 ms1096 KiB
#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,nx[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) { return (nx[x]==x?x:nx[x]=find(nx[x])); } int get(int x) { int now=-1; while(x){ now=find(now+1); 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) nx[i]=i; m=n; while(1){ l=1;r=m; while(l<r){ mid=l+r>>1; x=get(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=get(l); if(s[0]+s[1]==0)return x; nx[x]=nx[x+1]; T.add(x); } }

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:66:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   66 |    mid=l+r>>1;
      |        ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...