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 "seats.h"
#include <bits/stdc++.h>
using namespace std;
void chmin(int& a,int b){a=min(a,b);}
void chmax(int& a,int b){a=max(a,b);}
vector<int> r,c,xmi,xma,ymi,yma;
int h,w,cnt;
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
r=R;
c=C;
h=H;
w=W;
xmi.resize(H*W);
xma.resize(H*W);
ymi.resize(H*W);
yma.resize(H*W);
xmi[0]=c[0],xma[0]=c[0],ymi[0]=r[0],yma[0]=r[0];
cnt=1;
for(int i=1;i<h*w;i++){
xmi[i]=xmi[i-1],ymi[i]=ymi[i-1],xma[i]=xma[i-1],yma[i]=yma[i-1];
chmin(xmi[i],c[i]);
chmin(ymi[i],r[i]);
chmax(xma[i],c[i]);
chmax(yma[i],r[i]);
if((xma[i]-xmi[i]+1)*(yma[i]-ymi[i]+1)==i+1){
cnt++;
}
}
}
int swap_seats(int a, int b) {
if(a>b)swap(a,b);
for(int i=a;i<=b;i++){
if((xma[i]-xmi[i]+1)*(yma[i]-ymi[i]+1)==i+1){
cnt--;
}
}
swap(r[a],r[b]);
swap(c[a],c[b]);
for(int i=a;i<=b;i++){
if(i>0){
xmi[i]=xmi[i-1],ymi[i]=ymi[i-1],xma[i]=xma[i-1],yma[i]=yma[i-1];
}else{
xmi[0]=c[0],xma[0]=c[0],ymi[0]=r[0],yma[0]=r[0];
}
chmin(xmi[i],c[i]);
chmin(ymi[i],r[i]);
chmax(xma[i],c[i]);
chmax(yma[i],r[i]);
if((xma[i]-xmi[i]+1)*(yma[i]-ymi[i]+1)==i+1){
cnt++;
}
}
return cnt;
}
# | 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... |