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 = 1e6 + 5, INF = 1e9, G = 5;
int n, m, len;
vector<int> x, y;
map<pair<int, int>, int> mp;
int dx[4] = { 0, 0, 1, 1 }, dy[4] = { 1, 0, 0, 1};
struct Node {
int mn, ct, up;
} t[N * 4];
Node operator + (Node a, Node b) {
if (a.mn == b.mn) {
a.ct += b.ct;
return a;
}
if (a.mn < b.mn)
return a;
return b;
}
void push(int v, int L, int R) {
if (t[v].up) {
if (L != R) {
t[v * 2].up += t[v].up;
t[v * 2 + 1].up += t[v].up;
}
t[v].mn += t[v].up;
t[v].up = 0;
}
}
void upd(int l, int r, int x, int v, int L, int R) {
push(v, L, R);
if (l > r)
return;
if (l == L && r == R) {
t[v].up += x;
push(v, L, R);
}
else {
int m = (L + R) >> 1;
upd(l, min(m, r), x, v * 2, L, m);
upd(max(m + 1, l), r, x, v * 2 + 1, m + 1, R);
t[v] = t[v * 2] + t[v * 2 + 1];
}
}
void change(int a, int b, int d) {
for (int i = 0; i < 4; i++) {
vector<pair<int, int>> v;
for (int j = 0; j < 4; j++) {
v.push_back({ a - dx[i] + dx[j], b - dy[i] + dy[j] });
}
sort(v.begin(), v.end(), [&](pair<int, int> p, pair<int, int> q) {
return mp[p] < mp[q];
});
for (int j = 0; j < 4; j++) {
if (mp[v[j]] == INF)
break;
if (j == 0) {
upd(mp[v[j]], min(len - 1, mp[v[j + 1]] - 1), d, 1, 0, len - 1);
}
else if (j == 2) {
upd(mp[v[j]], min(len - 1, mp[v[j + 1]] - 1), d * G, 1, 0, len - 1);
}
}
}
}
void que(int v, int L, int R) {
push(v, L, R);
if (L == R) {
cout << t[v].mn << " ";
}
else {
int m = (L + R) >> 1;
que(v * 2, L, m);
que(v * 2 + 1, m + 1, R);
}
}
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
n = H;
m = W;
x = R;
y = C;
len = n * m;
for (int i = 0; i <= n + 1; i++) {
for (int j = 0; j <= m + 1; j++) {
mp[{ i, j }] = INF;
}
}
fill(t, t + len * 4, (Node){0, 1, 0});
for (int i = 0; i < len; i++) {
x[i]++;
y[i]++;
change(x[i], y[i], -1);
mp[{ x[i], y[i] }] = i;
change(x[i], y[i], 1);
}
}
int swap_seats(int a, int b) {
change(x[a], y[a], -1);
mp[{ x[a], y[a] } ] = INF;
change(x[a], y[a], 1);
change(x[b], y[b], -1);
mp[{ x[b], y[b] }] = INF;
change(x[b], y[b], 1);
swap(x[a], x[b]);
swap(y[a], y[b]);
change(x[a], y[a], -1);
mp[{ x[a], y[a] } ] = a;
change(x[a], y[a], 1);
change(x[b], y[b], -1);
mp[{ x[b], y[b] }] = b;
change(x[b], y[b], 1);
push(1, 0, len - 1);
return t[1].mn == 4 ? t[1].ct : 0;
}
# | 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... |