이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "seats.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> R, C;
int h, w;
const int N=(1<<10);
int tab[N][N+N], tab2[N][N+N];
void give_initial_chart(int H, int W, std::vector<int> R2, std::vector<int> C2) {
R=R2;
C=C2;
h=H;
w=W;
for(int i=0; i<W*H; i++){
tab[R[i]][N+C[i]]=i;
tab2[C[i]][N+R[i]]=i;
}
for(int i=0; i<N; i++){
for(int j=N-1; j>0; j--){
tab[i][j]=max(tab[i][j+j], tab[i][j+j+1]);
tab2[i][j]=max(tab2[i][j+j], tab2[i][j+j+1]);
}
}
}
void ust(int a, int id, int c){
for(id+=N, tab[a][id]=c, id>>=1; id; id>>=1){
tab[a][id]=max(tab[a][id+id], tab[a][id+id+1]);
}
}
int maks(int a, int l, int r){
int ans=0;
for(l+=N, r+=N; l<r; l>>=1, r>>=1){
if(l&1)ans=max(ans, tab[a][l++]);
if(r&1)ans=max(ans, tab[a][--r]);
}
return ans;
}
void ust2(int a, int id, int c){
for(id+=N, tab2[a][id]=c, id>>=1; id; id>>=1){
tab2[a][id]=max(tab2[a][id+id], tab2[a][id+id+1]);
}
}
int maks2(int a, int l, int r){
int ans=0;
for(l+=N, r+=N; l<r; l>>=1, r>>=1){
if(l&1)ans=max(ans, tab2[a][l++]);
if(r&1)ans=max(ans, tab2[a][--r]);
}
return ans;
}
int swap_seats(int a, int b) {
swap(R[a], R[b]);
swap(C[a], C[b]);
ust(R[a], C[a], a);
ust2(C[a], R[a], a);
ust(R[b], C[b], b);
ust2(C[b], R[b], b);
int x1=R[0], x2=R[0], y1=C[0], y2=C[0];
int M=0, ans=0;
while((x2-x1+1)*(y2-y1+1)<h*w){
if(M==(x2-x1+1)*(y2-y1+1)-1)ans++;
int t1=N*N, t2=N*N, t3=N*N, t4=N*N;
if(x1)t1=maks(x1-1, y1, y2+1);
if(x2<h-1)t2=maks(x2+1, y1, y2+1);
if(y1)t3=maks2(y1-1, x1, x2+1);
if(y2<w-1)t4=maks2(y2+1, x1, x2+1);
//cout<<x1<<" "<<x2<<" "<<y1<<" "<<y2<<"\n";
//cout<<M<<"\n";
//cout<<t1<<" "<<t2<<"\n";
//cout<<t3<<" "<<t4<<"\n";
int k= min({t1, t2, t3, t4});
M=max(M, k);
if(t1==k)x1--;
if(t2==k)x2++;
if(t3==k)y1--;
if(t4==k)y2++;
}
return ans+1;
}
# | 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... |