This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
vector<int> r,c;
int h,w;
int cst[1000001];
int mnx[1000001];
int mny[1000001];
int mxx[1000001];
int mxy[1000001];
int all = 0;
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++){
r.push_back(R[i]);
c.push_back(C[i]);
}
mnx[0] = 1e9;
mny[0] = 1e9;
mxx[0] = -1e9;
mxy[0] = -1e9;
for(int i = 0;i<h*w;i++){
mnx[i+1] = min(mnx[i],r[i]);
mxx[i+1] = max(mxx[i],r[i]);
mny[i+1] = min(mny[i],c[i]);
mxy[i+1] = max(mxy[i],c[i]);
if(i+1==(mxx[i+1]-mnx[i+1]+1)*(mxy[i+1]-mny[i+1]+1)){
cst[i] = 1;
all++;
}
}
}
int swap_seats(int a, int b){
if(a>b)swap(a,b);
swap(r[a],r[b]);
swap(c[a],c[b]);
for(int i = a;i<b;i++){
all-=cst[i];
mnx[i+1] = min(mnx[i],r[i]);
mxx[i+1] = max(mxx[i],r[i]);
mny[i+1] = min(mny[i],c[i]);
mxy[i+1] = max(mxy[i],c[i]);
if(i+1==(mxx[i+1]-mnx[i+1]+1)*(mxy[i+1]-mny[i+1]+1)){
all++;
cst[i] = 1;
}
}
return all;
}
# | 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... |