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>
using namespace std;
#define in(i) cin >> i
#define out(o) cout << o
vector<int> prefmaxc;
vector<int> prefminc;
vector<int> prefmaxr;
vector<int> prefminr;
vector<int> R;
vector<int> C;
int ans = 0;
void give_initial_chart(int H, int W, vector<int> RL, vector<int> CL) {
prefmaxc.resize(H * W);
prefminc.resize(H * W);
prefmaxr.resize(H * W);
prefminr.resize(H * W);
R.resize(H * W);
C.resize(H * W);
int maxc = -1;
int minc = 1e9;
int maxr = -1;
int minr = 1e9;
for (int i = 0; i < H * W; i++) {
R[i] = RL[i];
C[i] = CL[i];
}
for (int i = 0; i < H * W; i++) {
maxc = max(maxc, C[i]);
minc = min(minc, C[i]);
maxr = max(maxr, R[i]);
minr = min(minr, R[i]);
prefmaxc[i] = maxc;
prefminc[i] = minc;
prefmaxr[i] = maxr;
prefminr[i] = minr;
if ((maxc - minc + 1) * (maxr - minr + 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 ((prefmaxc[i] - prefminc[i] + 1) * (prefmaxr[i] - prefminr[i] + 1) == i + 1) ans--;
}
int maxc = a? prefmaxc[a - 1]: -1;
int minc = a? prefminc[a - 1]: 1e9;
int maxr = a? prefmaxr[a - 1]: -1;
int minr = a? prefminr[a - 1]: 1e9;
for (int i = a; i < b; i++) {
maxc = max(maxc, C[i]);
minc = min(minc, C[i]);
maxr = max(maxr, R[i]);
minr = min(minr, R[i]);
prefmaxc[i] = maxc;
prefminc[i] = minc;
prefmaxr[i] = maxr;
prefminr[i] = minr;
if ((maxc - minc + 1) * (maxr - minr + 1) == i + 1) 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... |