Submission #75247

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