Submission #1094293

#TimeUsernameProblemLanguageResultExecution timeMemory
1094293alexddSanta Claus (RMI19_santa)C++17
100 / 100
322 ms13392 KiB
#include <bits/stdc++.h> using namespace std; int n; pair<int,int> aint[270000]; pair<int,int> emp = {0,0}; pair<int,int> combine(pair<int,int> x, pair<int,int> y) { return {x.first + y.first, min(x.second, x.first + y.second)}; } void upd(int nod, int st, int dr, int poz, int newv) { if(st==dr) { aint[nod].first += newv; aint[nod].second += newv; return; } int mij=(st+dr)/2; if(poz<=mij) upd(nod*2,st,mij,poz,newv); else upd(nod*2+1,mij+1,dr,poz,newv); aint[nod] = combine(aint[nod*2], aint[nod*2+1]); } int x[100000],h[100000],v[100000]; int rez[100000]; signed main() { int t; cin>>t; while(t--) { cin>>n; for(int i=0;i<min(4*n+2,270000);i++) aint[i] = emp; int ult0=0; for(int i=1;i<=n;i++) cin>>x[i]; for(int i=1;i<=n;i++) { cin>>h[i]; if(h[i]==0) ult0=i; rez[i] = -1; } for(int i=1;i<=n;i++) cin>>v[i]; set<pair<int,int>> s; for(int i=1;i<=ult0;i++) { if(h[i]==0) upd(1,1,n,v[i],-1); else upd(1,1,n,v[i],+1); } int st=1; for(int dr=ult0;dr<=n;dr++) { if(dr>ult0) { assert(h[dr]==1); upd(1,1,n,v[dr],+1); } while(st<=dr && aint[1].second>=0) { if(h[st]==0) { s.insert({v[st],st}); } else { upd(1,1,n,v[st],-1); auto it = s.lower_bound({v[st],-1}); if(it!=s.end()) { upd(1,1,n,(*it).first,+1); s.erase(it); } } st++; } if(st==1) rez[dr] = -1; else rez[dr] = 2*x[dr] - x[st-1]; } for(int i=1;i<=n;i++) cout<<rez[i]<<" "; cout<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...