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 BASE = 1000;
int H, W, N, cx[1000009], cy[1000009], lx[1000009], ly[1000009], rx[1000009], ry[1000009], sum;
priority_queue<int, vector<int>, greater<int>> A1[1009], A2[1009];
int A[1009][1009];
int calc(int p1, int p2, int p3, int p4) {
return (p3 - p1 + 1) * (p4 - p2 + 1);
}
void refresh(int L, int R) {
for (int i = L; i <= R; i++) {
if (calc(lx[i], ly[i], rx[i], ry[i]) == i) sum--;
lx[i] = min(lx[i - 1], cx[i - 1]);
ly[i] = min(ly[i - 1], cy[i - 1]);
rx[i] = max(rx[i - 1], cx[i - 1]);
ry[i] = max(ry[i - 1], cy[i - 1]);
if (calc(lx[i], ly[i], rx[i], ry[i]) == i) sum++;
}
}
void give_initial_chart(int HH, int WW, std::vector<int> RR, std::vector<int> CC) {
H = HH; W = WW; N = H * W;
for (int i = 0; i < N; i++) {
cx[i] = RR[i]; cy[i] = CC[i]; if (H <= BASE && W <= BASE) A[cx[i]][cy[i]] = i;
}
if (H <= BASE && W <= BASE) {
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) { A1[i].push(A[i][j]); A2[j].push(A[i][j]); }
}
}
else {
for (int i = 0; i <= N; i++) { lx[i] = H; ly[i] = W; rx[i] = -100; ry[i] = -100; }
refresh(1, N);
}
}
int solve() {
vector<pair<int, int>> I1, I2; vector<int>J;
for (int i = 0; i < H; i++) { I1.push_back(make_pair(A1[i].top(), i)); J.push_back(A1[i].top()); }
for (int i = 0; i < W; i++) { I2.push_back(make_pair(A2[i].top(), i)); J.push_back(A2[i].top()); }
sort(I1.begin(), I1.end());
sort(I2.begin(), I2.end());
sort(J.begin(), J.end()); J.erase(unique(J.begin(), J.end()), J.end()); J.push_back(N);
int LX = (1<<30), LY = (1<<30), RX = 0, RY = 0, c1 = 0, c2 = 0, sums = 0;
for (int i = 0; i < J.size() - 1; i++) {
while (c1 < I1.size() && I1[c1].first <= J[i]) {
LX = min(LX, I1[c1].second);
RX = max(RX, I1[c1].second);
c1++;
}
while (c2 < I2.size() && I2[c2].first <= J[i]) {
LY = min(LY, I2[c2].second);
RY = max(RY, I2[c2].second);
c2++;
}
int S = (RX - LX + 1) * (RY - LY + 1);
if (J[i] + 1 <= S && S <= J[i + 1]) sums++;
}
return sums;
}
int swap_seats(int a, int b) {
if (a > b) swap(a, b);
swap(cx[a], cx[b]);
swap(cy[a], cy[b]);
if (H <= BASE && W <= BASE) {
A1[cx[a]].push(a); A2[cy[a]].push(a); A1[cx[b]].push(b); A2[cy[b]].push(b);
while (!A1[cx[a]].empty()) { int Z = A1[cx[a]].top(); if (cx[Z] == cx[a]) break; A1[cx[a]].pop(); }
while (!A1[cx[b]].empty()) { int Z = A1[cx[b]].top(); if (cx[Z] == cx[b]) break; A1[cx[b]].pop(); }
while (!A2[cy[a]].empty()) { int Z = A2[cy[a]].top(); if (cy[Z] == cy[a]) break; A2[cy[a]].pop(); }
while (!A2[cy[b]].empty()) { int Z = A2[cy[b]].top(); if (cy[Z] == cy[b]) break; A2[cy[b]].pop(); }
return solve();
}
else {
refresh(a + 1, b + 1);
return sum;
}
}
Compilation message (stderr)
seats.cpp: In function 'int solve()':
seats.cpp:50:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < J.size() - 1; i++) {
~~^~~~~~~~~~~~~~
seats.cpp:51:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (c1 < I1.size() && I1[c1].first <= J[i]) {
~~~^~~~~~~~~~~
seats.cpp:56:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (c2 < I2.size() && I2[c2].first <= J[i]) {
~~~^~~~~~~~~~~
# | 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... |