Submission #995531

#TimeUsernameProblemLanguageResultExecution timeMemory
995531CSQ31Robots (IOI13_robots)C++17
100 / 100
1102 ms21072 KiB
#pragma GCC optimize("Ofast") #include "robots.h" #include<bits/stdc++.h> using namespace std; #define fi first #define se second typedef pair<int,int> pii; struct fenwick{ int n; vector<int>bit; void upd(int pos,int val){ for(int i=pos;i<=n;i+=i&(-i))bit[i]+=val; } int query(int r){ int res = 0; for(int i=r;i>0;i-=i&(-i))res+=bit[i]; return res; } int search(int val){ int sum = 0,pos = 0; for(int i=19;i>=0;i--){ if(pos+(1<<i) < n && sum+bit[pos+(1<<i)]<val){ pos+=(1<<i); sum+=bit[pos]; } } return pos+1; } fenwick(int _n){ n = _n; bit.assign(n+1,0); } }; int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { vector<int>x,y; for(int i=0;i<A;i++)x.push_back(X[i]); for(int i=0;i<B;i++)y.push_back(Y[i]); sort(x.begin(),x.end()); sort(y.begin(),y.end()); vector<pii>pt(T); for(int i=0;i<T;i++){ W[i] = lower_bound(x.begin(),x.end(),W[i]+1) - x.begin(); S[i] = lower_bound(y.begin(),y.end(),S[i]+1) - y.begin(); pt[i] = {W[i],S[i]}; } // for(pii x:pt)cout<<x.fi<<" "<<x.se<<'\n'; sort(pt.begin(),pt.end()); int l = 1,r = T; while(r>=l){ int mid = (l+r)/2; fenwick f(B+1); int p = 0,tot = 0; for(int i=0;i<A;i++){ while(p<T && pt[p].fi <= i){ f.upd(pt[p].se+1,1); tot++; p++; } for(int j=0;j<mid;j++){ if(!tot)break; int k = f.search(tot); f.upd(k,-1); tot--; } } while(p!=T){ f.upd(pt[p].se+1,1); tot++; p++; } //cout<<mid<<'\n'; // for(int i=1;i<=B+1;i++)cout<<f.query(i)<<" "; // cout<<'\n'; bool ok = 1; if(tot - f.query(B))ok = 0; for(int i=0;i<B;i++){ int sum = tot - f.query(i); if(sum > mid * 1LL* (B-i))ok = 0; } if(ok)r = mid-1; else l = mid+1; } if(l == T+1)return -1; return l; }
#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...