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 "iostream"
#ifndef EVAL
#include "grader.cpp"
#endif
using namespace std;
vector<int> r, c;
vector<int> minx, maxx, miny, maxy;
int n, m;
int ans = 0;
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
n = H;
m = W;
r = R;
c = C;
minx.resize(n * m, n);
maxx.resize(n * m, -1);
miny.resize(n * m, m);
maxy.resize(n * m, -1);
for (int i = 0; i < n * m; i++) {
if (i == 0) {
minx[i] = maxx[i] = r[i];
miny[i] = maxy[i] = c[i];
} else {
minx[i] = min(minx[i - 1], r[i]);
maxx[i] = max(maxx[i - 1], r[i]);
miny[i] = min(miny[i - 1], c[i]);
maxy[i] = max(maxy[i - 1], c[i]);
}
if ((maxx[i] - minx[i] + 1) * (maxy[i] - miny[i] + 1) == i + 1) {
ans++;
}
}
}
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++) {
if ((maxx[i] - minx[i] + 1) * (maxy[i] - miny[i] + 1) == i + 1) {
ans--;
}
if (i == 0) {
minx[i] = maxx[i] = r[i];
miny[i] = maxy[i] = c[i];
} else {
minx[i] = min(minx[i - 1], r[i]);
maxx[i] = max(maxx[i - 1], r[i]);
miny[i] = min(miny[i - 1], c[i]);
maxy[i] = max(maxy[i - 1], c[i]);
}
if ((maxx[i] - minx[i] + 1) * (maxy[i] - miny[i] + 1) == i + 1) {
ans++;
}
}
return ans;
}
/*
2 3 2
0 0
1 0
1 1
0 1
0 2
1 2
0 5
0 5
*/
# | 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... |