# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
117996 | Osama_Alkhodairy | Seats (IOI18_seats) | C++17 | 0 ms | 0 KiB |
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];
vector <int> x, y;
int cur;
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]);
}
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);
cur += check(i);
}
}
int swap_seats(int a, int b) {
if(a > b) swap(a, b);
for(int i = a ; i <= b ; i++){
cur -= check(i);
}
swap(x[a], x[b]);
swap(y[a], y[b]);
for(int i = a ; i <= b ; i++){
update(i);
cur += check(i);
}
return cur;
}