#include "seats.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> r, c;
vector<vector<int>> mat;
int n, m;
void give_initial_chart(int _n, int _m, vector<int> _r, vector<int> _c) {
r = _r; c = _c;
n = _n; m = _m;
mat.resize(n, vector<int>(m));
for (int i = 0; i < n * m; i++) {
mat[r[i]][c[i]] = i;
}
}
int swap_seats(int a, int b) {
swap(r[a], r[b]);
swap(c[a], c[b]);
swap(mat[r[a]][c[a]], mat[r[b]][c[b]]);
int ans = 1;
int up = r[0], down = r[0];
int left = c[0], right = c[0];
int ma = 0;
for (int i = 1; i < n * m; i++) {
bool flag = 0;
while (up > r[i]) {
up--; flag = 1;
for (int j = left; j <= right; j++) ma = max(ma, mat[up][j]);
}
while (down < r[i]) {
down++; flag = 1;
for (int j = left; j <= right; j++) ma = max(ma, mat[down][j]);
}
while (left > c[i]) {
left--; flag = 1;
for (int j = up; j <= down; j++) ma = max(ma, mat[j][left]);
}
while (right < c[i]) {
right++; flag = 1;
for (int j = up; j <= down; j++) ma = max(ma, mat[j][right]);
}
int dim = (down - up + 1) * (right - left + 1);
if (flag && ma == dim - 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... |