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"
// #include "grader.cpp"
#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define OK puts("ok");
using namespace std;
const int N = (int)1e6 + 7;
pair < int, int > pos[N];
int h, w;
int ans;
int was[N];
int mxx[N], mnx[N], mny[N], mxy[N];
void give_initial_chart(int H, int W, vector<int> R, vector<int> C) {
tie(h, w) = make_tuple(H, W);
for (int i = 0; i < H * W; i++) {
pos[i] = mk(R[i], C[i]);
}
mnx[0] = mny[0] = pos[0].fr;
mxx[0] = mxy[0] = pos[0].sc;
ans = 1;
was[0] = 1;
for (int i = 1; i < h * w; i++) {
mnx[i] = min(mnx[i - 1], pos[i].fr);
mxx[i] = max(mxx[i - 1], pos[i].fr);
mny[i] = min(mny[i - 1], pos[i].sc);
mxy[i] = max(mxy[i - 1], pos[i].sc);
if (i + 1 == (mxx[i] - mnx[i] + 1) * (mxy[i] - mny[i] + 1)) {
ans++;
was[i] = 1;
}
}
}
int swap_seats(int a, int b) {
swap(pos[a], pos[b]);
for (int i = a; i <= b; i++) {
if (i > 0) {
mnx[i] = min(mnx[i - 1], pos[i].fr);
mxx[i] = max(mxx[i - 1], pos[i].fr);
mny[i] = min(mny[i - 1], pos[i].sc);
mxy[i] = max(mxy[i - 1], pos[i].sc);
} else {
mnx[i] = pos[i].fr;
mxx[i] = pos[i].fr;
mny[i] = pos[i].sc;
mxy[i] = pos[i].sc;
}
if (i + 1 == (mxx[i] - mnx[i] + 1) * (mxy[i] - mny[i] + 1)) {
if (!was[i]) {
was[i] = 1;
ans++;
}
} else {
if (was[i]) {
was[i] = 0;
ans--;
}
}
}
return ans;
}
# | 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... |