Submission #607402

#TimeUsernameProblemLanguageResultExecution timeMemory
607402Koosha_mvSeats (IOI18_seats)C++14
70 / 100
4022 ms103680 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; #define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl #define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl #define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl #define eror(x) cout<<#x<<'='<<(x)<<endl #define f_(i,a,b) for(int i=a;i>=b;i--) #define f(i,a,b) for(int i=a;i<b;i++) #define nb(x) __builtin_popcount(x) #define all(v) v.begin(),v.end() #define bit(n,k) (((n)>>(k))&1) #define maxm(a,b) a=max(a,b) #define minm(a,b) a=min(a,b) #define lst(x) x[x.size()-1] #define sz(x) int(x.size()) #define mp make_pair #define ll long long #define pb push_back #define S second #define F first const int N=1e6+99,dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; int n,m,t,lz[N<<2]; vector<int> a[N]; pair<int,int> seg[N<<2]; vector<int> A,B; pair<int,int> operator + (pair<int,int> A,pair<int,int> B){ if(A.F==B.F) A.S+=B.S; if(A.F<=B.F) return A; return B; } void upd(int id){ seg[id]=seg[id<<1]+seg[id<<1|1]; } void shift(int id){ lz[id<<1]+=lz[id]; lz[id<<1|1]+=lz[id]; seg[id<<1].F+=lz[id]; seg[id<<1|1].F+=lz[id]; lz[id]=0; } void debug(int id=1,int l=0,int r=t){ if(l+1==r){ cout<<l<<" -> "<<seg[id].F<<" "<<seg[id].S<<endl; return ; } int mid=(l+r)>>1; shift(id); debug(id<<1,l,mid); debug(id<<1|1,mid,r); upd(id); } void build(int id=1,int l=0,int r=t){ if(l+1==r){ seg[id]=mp(-(r)+(l==0),1); return ; } int mid=(l+r)>>1; build(id<<1,l,mid); build(id<<1|1,mid,r); upd(id); } void add(int L,int R,int val,int id=1,int l=0,int r=t){ if(r<=L || R<=l) return ; if(L<=l && r<=R){ lz[id]+=val; seg[id].F+=val; return ; } int mid=(l+r)>>1; shift(id); add(L,R,val,id<<1,l,mid); add(L,R,val,id<<1|1,mid,r); upd(id); } void Add(int l,int r,int val){ if(l==r) return ; if(r<l) swap(l,r); add(l,r,val); } void do_it(int x,int y,int p){ vector<pair<int,int>> vec; f(i,0,4){ int u=x+dx[i],v=y+dy[i]; vec.pb({a[u][v],i}); } sort(all(vec)); int l=max(a[x][y],vec[1].F),r=vec[2].F; if(l<r && (vec[0].S^2)==vec[1].S){ Add(l,r,p); } if(vec[1].F<a[x][y]){ Add(vec[1].F,a[x][y],(-p)*5); } Add(max(vec[3].F,a[x][y]),t,-p); } void updcell(int x,int y,int val){ //cout<<x<<" "<<y<<endl; f(i,0,4){ int u=x+dx[i],v=y+dy[i]; Add(a[x][y],a[u][v],-1); } a[x][y]=val; f(i,0,4){ int u=x+dx[i],v=y+dy[i]; Add(a[x][y],a[u][v],+1); } } void give_initial_chart(int _n, int _m,vector<int> _A,vector<int> _B) { n=_n,m=_m; A=_A,B=_B; t=n*m; f(i,0,t) A[i]++,B[i]++; vector<int> P(m+2,t); f(i,0,n+2) a[i]=P; f(i,0,t) a[A[i]][B[i]]=i; build(); //debug(); f(x,1,n+1){ f(y,1,m+1){ f(i,0,4){ int u=x+dx[i],v=y+dy[i]; //cout<<a[x][y]<<" -> "<<a[u][v]<<endl; if(a[x][y]<a[u][v]){ Add(a[x][y],a[u][v],1); } } } } f(x,1,n+1){ f(y,1,m+1){ do_it(x,y,-1); } } //debug(); //erorp(seg[1]); //cout<<"ans -> "<<seg[1].S*(seg[1].F==4)<<endl; } int swap_seats(int u, int v) { //eror(A[u]); //eror(A[v]); set<pair<int,int>> s; s.insert({A[u],B[u]}); s.insert({A[v],B[v]}); f(i,0,4){ int x=A[u]+dx[i],y=B[u]+dy[i]; if(1<=x & x<=n && 1<=y && y<=m) s.insert({x,y}); } f(i,0,4){ int x=A[v]+dx[i],y=B[v]+dy[i]; if(1<=x & x<=n && 1<=y && y<=m) s.insert({x,y}); } for(auto [x,y] : s){ do_it(x,y,+1); } updcell(A[u],B[u],v); updcell(A[v],B[v],u); swap(A[u],A[v]); swap(B[u],B[v]); for(auto [x,y] : s){ do_it(x,y,-1); } return seg[1].S*(seg[1].F==4); } /* 1 3 3 0 0 0 1 0 2 0 2 1 2 0 1 1 3 1 0 2 0 1 0 0 0 0 1 4 0 0 3 0 2 0 1 0 0 1 4 4 0 0 0 1 0 2 0 3 0 1 0 3 1 3 1 2 */

Compilation message (stderr)

seats.cpp: In function 'int swap_seats(int, int)':
seats.cpp:149:9: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
  149 |     if(1<=x & x<=n && 1<=y && y<=m) s.insert({x,y});
      |        ~^~~
seats.cpp:153:9: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
  153 |     if(1<=x & x<=n && 1<=y && y<=m) s.insert({x,y});
      |        ~^~~
seats.cpp:155:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  155 |   for(auto [x,y] : s){
      |            ^
seats.cpp:162:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  162 |   for(auto [x,y] : s){
      |            ^
#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...