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;
const int inf = 1e9;
struct item{
int mnx, mxx, mny, mxy;
};
item merge(item a, item b){
item c;
c.mnx = min(a.mnx, b.mnx);
c.mxx = max(a.mxx, b.mxx);
c.mny = min(a.mny, b.mny);
c.mxy = max(a.mxy, b.mxy);
return c;
}
int n, m;
item tree[4 * N];
vector <int> x, y;
void update(int l, int r, int node, int ind, item v){
if(r < l || r < ind || l > ind) return;
if(l == r){
tree[node] = v;
return;
}
int mid = (l + r) / 2;
update(l, mid, 2 * node, ind, v);
update(mid + 1, r, 2 * node + 1, ind, v);
tree[node] = merge(tree[2 * node], tree[2 * node + 1]);
}
item query(int l, int r, int node, int s, int e){
if(r < l || r < s || l > e) return item{inf, -inf, inf, -inf};
if(s <= l && r <= e) return tree[node];
int mid = (l + r) / 2;
return merge(query(l, mid, 2 * node, s, e), query(mid + 1, r, 2 * node + 1, s, e));
}
void update(int i){
update(0, n * m - 1, 1, i, item{x[i], x[i], y[i], y[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 area(int g){
item c = query(0, n * m - 1, 1, 0, g);
return (c.mxx - c.mnx + 1) * (c.mxy - c.mny + 1);
}
int swap_seats(int a, int b) {
swap(x[a], x[b]);
swap(y[a], y[b]);
update(a);
update(b);
int ret = 0;
int cur = 0;
while(cur < n * m){
int ar = area(cur);
if(ar == cur + 1){
ret++;
cur++;
}
else{
cur = ar - 1;
}
}
return ret;
}
# | 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... |