이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "seats.h"
#include <bits/stdc++.h>
using namespace std;
int H,W;
vector<pair<int,int>>XY;
int treeXmin[1<<21],treeXmax[1<<21],treeYmin[1<<21],treeYmax[1<<21];
int calcXmin(int l,int r){
int a=H;
l+=(1<<20);
r+=(1<<20);
while(l<=r){
a=min({a,treeXmin[l],treeXmin[r]});
l=(l+1)/2;
r=(r-1)/2;
}
return a;
}
int calcXmax(int l,int r){
int a=0;
l+=(1<<20);
r+=(1<<20);
while(l<=r){
a=max({a,treeXmax[l],treeXmax[r]});
l=(l+1)/2;
r=(r-1)/2;
}
return a;
}
int calcYmin(int l,int r){
int a=W;
l+=(1<<20);
r+=(1<<20);
while(l<=r){
a=min({a,treeYmin[l],treeYmin[r]});
l=(l+1)/2;
r=(r-1)/2;
}
return a;
}
int calcYmax(int l,int r){
int a=0;
l+=(1<<20);
r+=(1<<20);
while(l<=r){
a=max({a,treeYmax[l],treeYmax[r]});
l=(l+1)/2;
r=(r-1)/2;
}
return a;
}
int next_Xmin(int t,int m){
int k=t+(1<<20);
while(m<=treeXmin[k]&&k!=1){
k=(k+1)/2;
}
while(k<(1<<20)){
if(treeXmin[k+k]<m){
k=k+k;
}
else{
k=k+k+1;
}
}
return k-(1<<20);
}
int next_Xmax(int t,int m){
int k=t+(1<<20);
while(m>=treeXmax[k]&&k!=1){
k=(k+1)/2;
}
while(k<(1<<20)){
if(treeXmax[k+k]>m){
k=k+k;
}
else{
k=k+k+1;
}
}
return k-(1<<20);
}
int next_Ymin(int t,int m){
int k=t+(1<<20);
while(m<=treeYmin[k]&&k!=1){
k=(k+1)/2;
}
while(k<(1<<20)){
if(treeYmin[k+k]<m){
k=k+k;
}
else{
k=k+k+1;
}
}
return k-(1<<20);
}
int next_Ymax(int t,int m){
int k=t+(1<<20);
while(m>=treeYmax[k]&&k!=1){
k=(k+1)/2;
}
while(k<(1<<20)){
if(treeYmax[k+k]>m){
k=k+k;
}
else{
k=k+k+1;
}
}
return k-(1<<20);
}
void update(int x){
int t=x;
x+=(1<<20);
treeXmin[x]=treeXmax[x]=XY[t].first;
treeYmin[x]=treeYmax[x]=XY[t].second;
while(x){
x/=2;
treeXmin[x]=min(treeXmin[x+x],treeXmin[x+x+1]);
treeXmax[x]=max(treeXmax[x+x],treeXmax[x+x+1]);
treeYmin[x]=min(treeYmin[x+x],treeYmin[x+x+1]);
treeYmax[x]=max(treeYmax[x+x],treeYmax[x+x+1]);
}
}
void give_initial_chart(int h,int w,vector<int>R,vector<int>C){
H=h;
W=w;
for(int i=0;i<H*W;i++){
XY.push_back({R[i],C[i]});
}
for(int i=0;i<H*W;i++){
treeXmin[i+(1<<20)]=treeXmax[i+(1<<20)]=XY[i].first;
treeYmin[i+(1<<20)]=treeYmax[i+(1<<20)]=XY[i].second;
}
treeXmin[H*W+(1<<20)]=treeYmin[H*W+(1<<20)]=-0xE869120;
treeXmax[H*W+(1<<20)]=treeYmax[H*W+(1<<20)]=0xE869120;
for(int i=(1<<20)-1;i;i--){
treeXmin[i]=min(treeXmin[i+i],treeXmin[i+i+1]);
treeXmax[i]=max(treeXmax[i+i],treeXmax[i+i+1]);
treeYmin[i]=min(treeYmin[i+i],treeYmin[i+i+1]);
treeYmax[i]=max(treeYmax[i+i],treeYmax[i+i+1]);
}
}
int swap_seats(int a,int b){
swap(XY[a],XY[b]);
update(a);
update(b);
int res=0;
int t=0;
while(t<H*W){
int p,q,r,s;
p=calcXmax(0,t);
q=calcXmin(0,t);
r=calcYmax(0,t);
s=calcYmin(0,t);
if((p-q+1)*(r-s+1)==t+1){
res++;
}
t=max(t+1,min({next_Xmin(t,q),next_Xmax(t,p),next_Ymin(t,s),next_Ymax(t,r)})-1);
}
return res;
}
# | 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... |