이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |