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;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef double ld;
typedef complex<ld> point;
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cerr << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 1e6 + 10;
int n, m, r[maxn], c[maxn], lazy[maxn << 2];
pii seg[maxn << 2];
pii operator +(pii a, pii b){
if (a.F == b.F) return MP(a.F, a.S+b.S);
return min(a, b);
}
void build(int v, int l, int r){
seg[v] = {0, r-l};
if (l + 1 == r) return;
int mid = (l + r) >> 1;
build(v << 1, l, mid);
build(v << 1 | 1, mid, r);
}
void shift(int v, int l, int r);
void add(int v, int l, int r, int ql, int qr, int val){
if (v == 1){
}
if (qr <= l || r <= ql) return;
if (ql <= l && r <= qr){
seg[v].F += val;
lazy[v] += val;
return;
}
shift(v, l, r);
int mid = (l + r) >> 1;
add(v << 1, l, mid, ql, qr, val);
add(v << 1 | 1, mid, r, ql, qr, val);
seg[v] = seg[v << 1] + seg[v << 1 | 1];
}
void shift(int v, int l, int r){
if (lazy[v] == 0) return;
int mid = (l + r) >> 1;
add(v << 1, l, mid, l, mid, lazy[v]);
add(v << 1 | 1, mid, r, mid, r, lazy[v]);
lazy[v] = 0;
}
vector<int> a[maxn];
void check(int i, int j, int x){
int tmp[4] = {a[i][j], a[i][j-1], a[i-1][j], a[i-1][j-1]};
sort(tmp, tmp+4);
add(1, 0, n*m, tmp[0], tmp[1], x);
add(1, 0, n*m, tmp[2], tmp[3], x);
}
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
n = H;
m = W;
build(1, 0, n*m);
for (int i = 0; i <= n+1; i++){
a[i] = vector<int>(m+2, maxn);
}
for (int i = 0; i < n*m; i++){
r[i] = R[i]+1;
c[i] = C[i]+1;
a[r[i]][c[i]] = i;
}
for (int i = 1; i <= n+1; i++){
for (int j = 1; j <= m+1; j++){
check(i, j, 1);
}
}
}
int xc[4] = {0, 1, 0, 1};
int yc[4] = {0, 0, 1, 1};
void change(int x, int y, int c){
for (int i = 0; i < 4; i++){
int ux = x + xc[i];
int uy = y + yc[i];
check(ux, uy, c);
}
}
int swap_seats(int x, int y) {
change(r[x], c[x], -1);
a[r[x]][c[x]] = y;
change(r[x], c[x], 1);
change(r[y], c[y], -1);
a[r[y]][c[y]] = x;
change(r[y], c[y], 1);
swap(r[x], r[y]);
swap(c[x], c[y]);
return seg[1].S;
}
# | 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... |