이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "seats.h"
#include <bits/stdc++.h>
using namespace std;
int H,W,res;
vector<pair<int,int>>XY;
vector<int>Xmin,Xmax,Ymin,Ymax;
void give_initial_chart(int h,int w,vector<int>R,vector<int>C){
H=h;
W=w;
Xmin=Ymin=Xmax=Ymax=vector<int>(H*W);
for(int i=0;i<H*W;i++){
XY.push_back({R[i],C[i]});
}
Xmin[0]=Xmax[0]=XY[0].first;
Ymin[0]=Ymax[0]=XY[0].second;
for(int i=1;i<H*W;i++){
Xmin[i]=min(Xmin[i-1],XY[i].first);
Xmax[i]=max(Xmax[i-1],XY[i].first);
Ymin[i]=min(Ymin[i-1],XY[i].second);
Ymax[i]=max(Ymax[i-1],XY[i].second);
}
for(int i=0;i<H*W;i++){
if(i+1==(Xmax[i]-Xmin[i]+1)*(Ymax[i]-Ymin[i]+1)){
res++;
}
}
}
int swap_seats(int a,int b){
if(a>b)swap(a,b);
swap(XY[a],XY[b]);
if(!a){
Xmin[0]=Xmax[0]=XY[0].first;
Ymin[0]=Ymax[0]=XY[0].second;
}
for(int i=max(a,1);i<=b;i++){
if(i+1==(Xmax[i]-Xmin[i]+1)*(Ymax[i]-Ymin[i]+1)){
res--;
}
Xmin[i]=min(Xmin[i-1],XY[i].first);
Xmax[i]=max(Xmax[i-1],XY[i].first);
Ymin[i]=min(Ymin[i-1],XY[i].second);
Ymax[i]=max(Ymax[i-1],XY[i].second);
if(i+1==(Xmax[i]-Xmin[i]+1)*(Ymax[i]-Ymin[i]+1)){
res++;
}
}
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... |