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;
const int maxN=1000100;
struct node{int x,y,hi,hx,wi,wx,ans;}p[maxN];
int h,w;
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
h=H;w=W;
for (int i=0;i<H*W;i++){
p[i].x=R[i];p[i].y=C[i];
}
p[0].hi=p[0].hx=p[0].x;
p[0].wi=p[0].wx=p[0].y;
for (int i=1;i<h*w;i++){
p[i].hi=min(p[i].x,p[i-1].hi);
p[i].hx=max(p[i].x,p[i-1].hx);
p[i].wi=min(p[i].y,p[i-1].wi);
p[i].wx=max(p[i].y,p[i-1].wx);
}
}
int swap_seats(int a, int b){
int t=a,ans=0;
swap(p[a],p[b]);
p[0].hi=p[0].hx=p[0].x;
p[0].wi=p[0].wx=p[0].y;
int mi=min(a,b);
if(mi==0)mi=1;
for (int i=mi;i<=max(a,b);i++){
p[i].hi=min(p[i].x,p[i-1].hi);
p[i].hx=max(p[i].x,p[i-1].hx);
p[i].wi=min(p[i].y,p[i-1].wi);
p[i].wx=max(p[i].y,p[i-1].wx);
}
for (int i=0;i<h*w;){
int Hi=p[i].hi,Hx=p[i].hx,Wi=p[i].wi,Wx=p[i].wx;
if ((Hx-Hi+1)*(Wx-Wi+1)==i+1){ans++;i++;}
else i=(Hx-Hi+1)*(Wx-Wi+1)-1;
}
return ans;
}
Compilation message (stderr)
seats.cpp: In function 'int swap_seats(int, int)':
seats.cpp:23:6: warning: unused variable 't' [-Wunused-variable]
int t=a,ans=0;
^
# | 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... |