이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |