Submission #254562

#TimeUsernameProblemLanguageResultExecution timeMemory
254562MKopchevDancing Elephants (IOI11_elephants)C++14
26 / 100
9100 ms10704 KiB
#include "elephants.h" #include <bits/stdc++.h> using namespace std; const int nmax=1.5e5+42; int n,l,where[nmax]; set< pair<int/*position*/,int/*id*/> > active; int BLOCK; int which_block[nmax]; void init(int N,int L,int X[]) { n=N; l=L; for(int i=0;i<N;i++) { where[i]=X[i]; active.insert({where[i],i}); } BLOCK=sqrt(n)+1; } int IN=0; set< pair<int/*position*/,int/*id*/> > BLOCKS[nmax]; pair<int/*photos*/,int/*last from the same block*/> nxt[nmax]; pair<int/*position*/,int/*id*/> help[nmax]; int get_nxt(int who) { /* cout<<"who= "<<who<<endl; cout<<"where: ";for(int i=0;i<n;i++)cout<<where[i]<<" ";cout<<endl; cout<<"active: ";for(auto k:active)cout<<k.first<<" "<<k.second<<"\t";cout<<endl; */ int t=l+where[who]; t++; set< pair<int/*position*/,int/*id*/> >::iterator it=active.lower_bound({t,0}); if(it==active.end())return -1; return (*it).second; } int build_block(int which) { vector< pair<int/*position*/,int/*id*/> > given={}; for(auto k:BLOCKS[which]) given.push_back(k); for(int i=given.size()-1;i>=0;i--) { if(given[i].first+l>=given[given.size()-1].first)nxt[given[i].second]={0,given[i].second}; else { int moved=get_nxt(given[i].second); nxt[given[i].second]={nxt[moved].first+1,nxt[moved].second}; } } } void build() { for(int i=0;i<n;i++) help[i]={where[i],i}; sort(help,help+n); int total=(n-1)/BLOCK+1; for(int i=0;i<total;i++)BLOCKS[i]={}; for(int i=0;i<n;i++) BLOCKS[i/BLOCK].insert({help[i].first,help[i].second}); for(int i=0;i<total;i++) build_block(i); } int update(int id,int val) { if(n==1)return 1; if(IN==0)build(); IN=(IN+1)%BLOCK; active.erase({where[id],id}); BLOCKS[which_block[id]].erase({where[id],id}); build_block(which_block[id]); where[id]=val; set< pair<int/*position*/,int/*id*/> >::iterator it=active.lower_bound({where[id],id}); if(it==active.end())it--; int new_block=which_block[(*it).second]; which_block[id]=new_block; active.insert({where[id],id}); BLOCKS[which_block[id]].insert({where[id],id}); build_block(which_block[id]); int ret=0,who=(*active.begin()).second; while(who!=-1) { /* ret+=nxt[who].first; who=nxt[who].second; */ ret++; who=get_nxt(who); } return ret; } /* int N_,L_,X_[nmax]; int main() { cin>>N_>>L_; for(int i=0;i<N_;i++)cin>>X_[i]; init(N_,L_,X_); int q; cin>>q; for(int i=1;i<=q;i++) { int pos,val; cin>>pos>>val; cout<<update(pos,val)<<endl; } return 0; } */

Compilation message (stderr)

elephants.cpp: In function 'int build_block(int)':
elephants.cpp:70:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...