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 <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, x[N], y[N], mx[N], Mx[N], my[N], My[N], r;
void cal(int a[], int m[], int M[], int s, int e){
for(int i = s; i <= e; i++){
m[i] = min(m[i - 1], a[i]);
M[i] = max(M[i - 1], a[i]);
}
}
void ch(int s, int e, int x){
for(int i = s; i <= e; i++)
if(1LL * (Mx[i] - mx[i] + 1) * (My[i] - my[i] + 1) == i) r += x;
}
void give_initial_chart(int H, int W, vector<int> R, vector<int> C) {
n = H * W;
for(int i = 0; i < n; i++){
x[i + 1] = R[i];
y[i + 1] = C[i];
}
mx[0] = my[0] = N;
cal(x, mx, Mx, 1, n);
cal(y, my, My, 1, n);
ch(1, n, 1);
}
int swap_seats(int a, int b){ a++; b++;
if(a > b) swap(a, b);
swap(x[a], x[b]);
swap(y[a], y[b]);
ch(a, b - 1, -1);
cal(x, mx, Mx, a, b - 1);
cal(y, my, My, a, b - 1);
ch(a, b - 1, 1);
return r;
}
# | 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... |