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>
#include "seats.h"
using namespace std;
const int N = 1000001;
int h, w, n;
vector <int> r, c;
set <int> rs[N], cs[N];
void give_initial_chart(int H, int W, vector <int> R, vector <int> C) {
h = H;
w = W;
r = R;
c = C;
n = h * w;
for(int i = 0 ; i < H * W ; i++){
rs[r[i]].insert(i);
cs[c[i]].insert(i);
}
}
int swap_seats(int a, int b) {
int ret = 0;
rs[r[a]].erase(a);
cs[c[a]].erase(a);
rs[r[b]].erase(b);
cs[c[b]].erase(b);
swap(r[a], r[b]);
swap(c[a], c[b]);
rs[r[a]].insert(a);
cs[c[a]].insert(a);
rs[r[b]].insert(b);
cs[c[b]].insert(b);
set <int> ready;
for(int i = 0 ; i < h ; i++){
int cur = *rs[i].begin();
if(cur > 0) ready.insert(cur - 1);
ready.insert(cur);
}
for(int i = 0 ; i < w ; i++){
int cur = *cs[i].begin();
if(cur > 0) ready.insert(cur - 1);
ready.insert(cur);
}
ready.insert(n - 1);
int mnr = 1e9, mxr = -1, mnc = 1e9, mxc = -1;
for(auto &i : ready){
mnr = min(mnr, r[i]);
mnc = min(mnc, c[i]);
mxr = max(mxr, r[i]);
mxc = max(mxc, c[i]);
if((mxr - mnr + 1) * (mxc - mnc + 1) == i + 1) ret++;
}
return ret;
}
# | 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... |