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"
using namespace std;
const int N = 1000001;
int n, m, mnx[N], mny[N], mxx[N], mxy[N], tree[4 * N];
vector <int> x, y;
void update(int l, int r, int node, int ind, int val){
if(r < l || l > ind || r < ind) return;
if(l == r){
tree[node] = val;
return;
}
int mid = (l + r) / 2;
update(l, mid, 2 * node, ind, val);
update(mid + 1, r, 2 * node + 1, ind, val);
tree[node] = tree[2 * node] + tree[2 * node + 1];
}
bool check(int g){
return (mxx[g] - mnx[g] + 1) * (mxy[g] - mny[g] + 1) == g + 1;
}
void update(int i){
mnx[i] = i == 0 ? x[i] : min(x[i], mnx[i - 1]);
mxx[i] = i == 0 ? x[i] : max(x[i], mxx[i - 1]);
mny[i] = i == 0 ? y[i] : min(y[i], mny[i - 1]);
mxy[i] = i == 0 ? y[i] : max(y[i], mxy[i - 1]);
update(0, n * m - 1, 1, i, check(i));
}
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
n = H;
m = W;
x = R;
y = C;
for(int i = 0 ; i < n * m ; i++){
update(i);
}
}
int swap_seats(int a, int b) {
if(a > b) swap(a, b);
swap(x[a], x[b]);
swap(y[a], y[b]);
for(int i = a ; i <= b ; i++){
update(i);
}
return tree[1];
}
# | 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... |