제출 #212823

#제출 시각아이디문제언어결과실행 시간메모리
212823MarcoMeijerSeats (IOI18_seats)C++14
0 / 100
4074 ms71160 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; //macros typedef long long ll; typedef pair<int, int> ii; typedef tuple<int, int, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<ll> vll; #define REP(a,b,c) for(int a=int(b); a<int(c); a++) #define RE(a,c) REP(a,0,c) #define RE1(a,c) REP(a,1,c+1) #define REI(a,b,c) REP(a,b,c+1) #define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--) #define INF 1e9 #define pb push_back #define fi first #define se second mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T, int DEF=0> class Seg { public: vi SEG; int sz; T t; void resize(int _sz) { sz = _sz; SEG.resize(sz*4); } void build(int p=0, int l=0, int r=-1) { if(r == -1) r = sz-1; if(l == r) { SEG[p] = 0; return; } int m=(l+r)/2; build(p*2+1,l,m); build(p*2+2,m+1,r); if(t(SEG[p*2+1], SEG[p*2+2])) SEG[p] = SEG[p*2+1]; else SEG[p] = SEG[p*2+2]; } int get(int i, int j, int p=0, int l=0, int r=-1) { if(r == -1) r = sz-1; if(j < l || i > r) return DEF; if(i <= l && j >= r) return SEG[p]; int m=(l+r)/2; int a=get(i,j,p*2+1,l,m); int b=get(i,j,p*2+2,m+1,r); if(t(a,b)) return a; else return b; } void set(int i, int x, int p=0, int l=0, int r=-1) { if(r == -1) r = sz-1; if(i < l || i > r) return; if(l == r) { SEG[p] = x; return; } int m=(l+r)/2; set(i,x,p*2+1,l,m); set(i,x,p*2+2,m+1,r); if(t(SEG[p*2+1], SEG[p*2+2])) SEG[p] = SEG[p*2+1]; else SEG[p] = SEG[p*2+2]; } }; int h, w, n; vi r, c; vector<Seg<greater<int>>> maxR; vector<Seg<greater<int>>> maxC; void give_initial_chart(int H, int W, vi R, vi C) { h=H, w=W, r=R, c=C; n = h*w; maxR.resize(h); maxC.resize(w); RE(i,h) maxR[i].resize(w); RE(i,w) maxC[i].resize(h); RE(i,n) maxR[r[i]].set(c[i],i); RE(i,n) maxC[c[i]].set(r[i],i); } int swap_seats(int a, int b) { if(b < a) swap(a,b); swap(r[a], r[b]); swap(c[a], c[b]); maxR[r[a]].set(c[a],a); maxR[r[b]].set(c[b],b); maxC[c[a]].set(r[a],a); maxC[c[b]].set(r[b],b); int cnt = 0; int cMinR = r[0]; int cMaxR = r[0]; int cMinC = c[0]; int cMaxC = c[0]; int i = 0; while(1) { if(i == (cMaxR-cMinR+1)*(cMaxC-cMinC+1)-1) cnt++; if(i == n-1) break; int mn=INF; if(cMinR != 0 ) mn = min(mn, maxR[cMinR-1].get(cMinC, cMaxC)); if(cMinC != 0 ) mn = min(mn, maxC[cMinC-1].get(cMinR, cMaxR)); if(cMaxR != h-1) mn = min(mn, maxR[cMaxR+1].get(cMinC, cMaxC)); if(cMaxC != w-1) mn = min(mn, maxC[cMaxC+1].get(cMinR, cMaxR)); if(cMinR != 0 && mn==maxR[cMinR-1].get(cMinC, cMaxC)) cMinR--; else if(cMinC != 0 && mn==maxC[cMinC-1].get(cMinR, cMaxR)) cMinC--; else if(cMaxR != h-1 && mn==maxR[cMaxR+1].get(cMinC, cMaxC)) cMaxR++; else if(cMaxC != w-1 && mn==maxC[cMaxC+1].get(cMinR, cMaxR)) cMaxC++; i = max(i, mn); } return cnt; }
#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...