(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #789577

#TimeUsernameProblemLanguageResultExecution timeMemory
789577alexander707070Seats (IOI18_seats)C++14
100 / 100
2342 ms134164 KiB
#include<bits/stdc++.h> #define MAXN 1000007 using namespace std; int n,m,x,y; vector<int> st[MAXN]; pair<int,int> pos[MAXN]; pair<int,int> tree[4*MAXN]; int lazy[4*MAXN]; void psh(int v){ tree[2*v].first+=lazy[v]; lazy[2*v]+=lazy[v]; tree[2*v+1].first+=lazy[v]; lazy[2*v+1]+=lazy[v]; lazy[v]=0; } pair<int,int> combine(pair<int,int> fr,pair<int,int> sc){ if(fr.first<sc.first)return fr; if(fr.first>sc.first)return sc; return {fr.first,fr.second+sc.second}; } void update(int v,int l,int r,int ll,int rr,int val){ if(ll>rr)return; if(l==ll and r==rr){ tree[v].first+=val; lazy[v]+=val; }else{ psh(v); int tt=(l+r)/2; update(2*v,l,tt,ll,min(tt,rr),val); update(2*v+1,tt+1,r,max(tt+1,ll),rr,val); tree[v]=combine(tree[2*v],tree[2*v+1]); } } vector<int> w; void updatesq(int x,int y,int val){ w={st[x][y], st[x][y+1], st[x+1][y], st[x+1][y+1]}; sort(w.begin(),w.end()); update(1,1,n*m,w[0],w[1]-1,val); update(1,1,n*m,w[2],w[3]-1,val); } void give_initial_chart(int H, int W,vector<int> R,vector<int> C){ n=H; m=W; for(int i=0;i<=n+1;i++){ for(int f=0;f<=m+1;f++){ st[i].push_back(n*m+1); } } for(int i=1;i<=n*m;i++){ st[R[i-1]+1][C[i-1]+1]=i; pos[i-1]={R[i-1]+1,C[i-1]+1}; } for(int i=1;i<=4*n*m;i++){ tree[i].second=1; } for(int i=0;i<=n;i++){ for(int f=0;f<=m;f++){ updatesq(i,f,1); } } } int swap_seats(int a, int b){ x=pos[a].first; y=pos[a].second; updatesq(x-1,y-1,-1); updatesq(x-1,y,-1); updatesq(x,y,-1); updatesq(x,y-1,-1); x=pos[b].first; y=pos[b].second; updatesq(x-1,y-1,-1); updatesq(x-1,y,-1); updatesq(x,y,-1); updatesq(x,y-1,-1); swap(st[pos[a].first][pos[a].second],st[pos[b].first][pos[b].second]); swap(pos[a],pos[b]); x=pos[a].first; y=pos[a].second; updatesq(x-1,y-1,1); updatesq(x-1,y,1); updatesq(x,y,1); updatesq(x,y-1,1); x=pos[b].first; y=pos[b].second; updatesq(x-1,y-1,1); updatesq(x-1,y,1); updatesq(x,y,1); updatesq(x,y-1,1); return tree[1].second; } /* int main(){ //give_initial_chart(1,6,{0,0,0,0,0,0},{0,1,2,3,4,5}); //cout<<swap_seats(0,2)<<"\n"; //cout<<swap_seats(0,5)<<"\n"; give_initial_chart(2, 3, {0, 1, 1, 0, 0, 1}, {0, 0, 1, 1, 2, 2}); cout<<swap_seats(0,5)<<"\n"; cout<<swap_seats(0,5)<<"\n"; } */
#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...