제출 #98318

#제출 시각아이디문제언어결과실행 시간메모리
98318fefe자리 배치 (IOI18_seats)C++17
25 / 100
4038 ms200620 KiB
#include "seats.h" #include<bits/stdc++.h> #define MAX_N 1000005 #define pb push_back #define all(v) (v).begin(),(v).end() #define fi first #define se second using namespace std; typedef pair<int,int> pii; int h,w; std::vector<int> r; pii V[MAX_N]; vector<int> lst; struct inout_pq{ priority_queue<int> in,out; void add(int x){in.push(-x);} void delect(int x){out.push(-x);} int return_top(){ while(in.size() && out.size() && in.top()==out.top()){in.pop(),out.pop();} if(in.size()) return -in.top(); return 0; } }X[MAX_N],Y[MAX_N]; void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { int i; h=H;w=W; for(i=0;i<H*W;i++){ V[i]={R[i],C[i]}; X[R[i]].add(i); Y[C[i]].add(i); } } int swap_seats(int a, int b) { int i; X[V[a].fi].delect(a);Y[V[a].se].delect(a); X[V[b].fi].delect(b);Y[V[b].se].delect(b); swap(V[a],V[b]); X[V[a].fi].add(a);Y[V[a].se].add(a); X[V[b].fi].add(b);Y[V[b].se].add(b); lst.clear();lst.resize(0); for(i=0;i<h;i++) lst.pb(X[i].return_top()); for(i=0;i<w;i++) lst.pb(Y[i].return_top()); sort(all(lst));lst.erase(unique(all(lst)),lst.end()); pii x,y; int ans=1; x={V[0].fi,V[0].fi};y={V[0].se,V[0].se}; for(int p:lst){ ans+=((x.se-x.fi+1)*(y.se-y.fi+1)==(p)); y.fi=min(y.fi,V[p].se);y.se=max(y.se,V[p].se); x.fi=min(x.fi,V[p].fi);x.se=max(x.se,V[p].fi); } return ans; }
#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...