Submission #704650

#TimeUsernameProblemLanguageResultExecution timeMemory
704650bin9638The Potion of Great Power (CEOI20_potion)C++17
38 / 100
899 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define fs first #define sc second #define N 200010 #define pb push_back #define ii pair<int,int> int n,D,H[N]; struct IT { struct node { int l,r,l_child,r_child; vector<int>lis; }; vector<node>ST; void init(int U) { ST.pb({1,U,-1,-1,{}}); } void update(int id,int u,int v,int val) { int l=ST[id].l,r=ST[id].r; if(l>v||r<u) return; if(l>=u&&r<=v) { ST[id].lis.pb(val); return; } int mid=(l+r)/2; if(ST[id].l_child==-1) ST[id].l_child=ST.size(),ST.pb({l,mid,-1,-1,{}}); if(ST[id].r_child==-1) ST[id].r_child=ST.size(),ST.pb({mid+1,r,-1,-1,{}}); update(ST[id].l_child,u,v,val); update(ST[id].r_child,u,v,val); } void solve(int id,int i,vector<int>&s) { if(id==-1) return; int l=ST[id].l,r=ST[id].r; if(l>i||r<i) return; for(auto u:ST[id].lis) s.pb(u); if(l==r) return; if(ST[id].l_child!=-1) solve(ST[id].l_child,i,s); if(ST[id].r_child!=-1) solve(ST[id].r_child,i,s); } }T[N]; void init(int num, int cc, int heigh[]) { n=num; D=cc; for(int i=0;i<n;i++) H[i]=heigh[i];//,cout<<H[i]<<endl; } map<ii,int>mp; void curseChanges(int U, int A[], int B[]) { for(int i=0;i<n;i++) T[i].init(U); for(int i=0;i<U;i++) { if(A[i]>B[i]) swap(A[i],B[i]); if(mp[{A[i],B[i]}]!=0) { T[A[i]].update(0,mp[{A[i],B[i]}],i,B[i]); T[B[i]].update(0,mp[{A[i],B[i]}],i,A[i]); //cout<<A[i]<<" "<<B[i]<<endl; mp[{A[i],B[i]}]=0; }else { mp[{A[i],B[i]}]=i+1; } } for(int i=0;i<U;i++) if(mp[{A[i],B[i]}]!=0) { //cout<<A[i]<<" "<<B[i]<<endl; T[A[i]].update(0,mp[{A[i],B[i]}],U,B[i]); T[B[i]].update(0,mp[{A[i],B[i]}],U,A[i]); mp[{A[i],B[i]}]=0; } } bool SS(const int&u,const int&v) { return H[u]<H[v]; } int question(int x, int y, int v) { int res=1000000000; vector<int>L,R; T[x].solve(0,v,L); T[y].solve(0,v,R); sort(L.begin(),L.end(),SS); sort(R.begin(),R.end(),SS); if(L.empty()||R.empty()) return res; for(int i=0,pos=0;i<L.size();i++) { while(pos<R.size()-1&&H[R[pos]]<=H[L[i]]) { res=min(res,abs(H[L[i]]-H[R[pos]])); pos++; } res=min(res,abs(H[L[i]]-H[R[pos]])); } return res; } #ifdef SKY int main() { freopen("A.inp","r",stdin); freopen("A.out","w",stdout); ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n,D; cin>>n>>D; int H[n]; for(int i=0;i<n;i++) cin>>H[i]; init(n,D,H); int m; cin>>m; int A[m],B[m]; for(int i=0;i<m;i++) cin>>A[i]; for(int i=0;i<m;i++) cin>>B[i]; curseChanges(m,A,B); int q; cin>>q; while(q--) { int x,y,T; cin>>x>>y>>T; cout<<question(x,y,T)<<endl; } return 0; } #endif // SKY

Compilation message (stderr)

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:118:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |     for(int i=0,pos=0;i<L.size();i++)
      |                       ~^~~~~~~~~
potion.cpp:120:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |         while(pos<R.size()-1&&H[R[pos]]<=H[L[i]])
      |               ~~~^~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...