Submission #75257

#TimeUsernameProblemLanguageResultExecution timeMemory
75257jangwonyoungSeats (IOI18_seats)C++14
100 / 100
3748 ms103740 KiB
#include "seats.h" #include<iostream> #include<algorithm> using namespace std; int n,m,k; int posx[1000001],posy[1000001]; vector<vector<int> >num; int minv[2097152],minc[2097152]; int lazy[2097152]; int a[5]; inline void build(int id,int l,int r){ minc[id]=r-l+1; if(l==r) return; int mid=(l+r)/2; build(id*2,l,mid); build(id*2+1,mid+1,r); } inline void supd(int id,int l,int r,int ll,int rr,int v){ if(l>rr || r<ll) return; if(ll<=l && r<=rr){ lazy[id]+=v; minv[id]+=v; return; } int mid=(l+r)/2; supd(id*2,l,mid,ll,rr,v); supd(id*2+1,mid+1,r,ll,rr,v); int lc=id*2,rc=id*2+1; if(minv[lc]<minv[rc]) minv[id]=minv[lc],minc[id]=minc[lc]; else if(minv[lc]>minv[rc]) minv[id]=minv[rc],minc[id]=minc[rc]; else minv[id]=minv[lc],minc[id]=minc[lc]+minc[rc]; minv[id]+=lazy[id]; } inline void upd(int x,int y,int v){ a[0]=num[x][y]; a[1]=num[x][y-1]; a[2]=num[x-1][y]; a[3]=num[x-1][y-1]; sort(a,a+4); //cout << "UPD " << x << ' ' << y << ' ' << a[1] << ' ' << a[2] << ' ' << a[3] << ' ' << a[4] << ' ' << v << endl;; if(a[0]<a[1]) supd(1,0,k-1,a[0],a[1]-1,v); if(a[2]<a[3]) supd(1,0,k-1,a[2],a[3]-1,v); } inline void change(int x,int y,int v){ upd(x,y,-1); upd(x+1,y,-1); upd(x,y+1,-1); upd(x+1,y+1,-1); num[x][y]=v; upd(x,y,1); upd(x+1,y,1); upd(x,y+1,1); upd(x+1,y+1,1); } void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { n=H; m=W; k=n*m; n+=2; m+=2; num.resize(n); for(int i=0; i<n ;i++){ num[i].resize(m); num[i][0]=num[i][m-1]=k; } for(int i=0; i<m ;i++){ num[0][i]=num[n-1][i]=k; } build(1,0,k-1); for(int i=0; i<k ;i++){ R[i]++; C[i]++; posx[i]=R[i]; posy[i]=C[i]; num[posx[i]][posy[i]]=i; } for(int i=1; i<n ;i++) for(int j=1; j<m ;j++) upd(i,j,1); } int swap_seats(int a, int b) { change(posx[a],posy[a],b); change(posx[b],posy[b],a); swap(posx[a],posx[b]); swap(posy[a],posy[b]); return minc[1];//minv must be 4 }
#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...