Submission #74129584
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
int main() {
int H, W, h, w, N;
cin >> H >> W >> h >> w >> N;
vector<int> blockT(N), blockB(N), blockL(N), blockR(N);
vector<pair<pair<int, int>, int>> actI;
vector<int> actPoints;
for (int i = 0; i < N; ++i) {
int r, c; cin >> r >> c;
blockT[i] = r-h+1, blockB[i] = r; // not doing max(..., 1)
blockL[i] = max(c-w+1, 1), blockR[i] = c;
actI.push_back({{blockL[i], +1}, i});
actI.push_back({{blockR[i]+1, -1}, i});
actPoints.push_back(blockL[i]);
actPoints.push_back(blockR[i]+1);
}
sort(actI.begin(), actI.end());
sort(actPoints.begin(), actPoints.end());
actPoints.resize(unique(actPoints.begin(), actPoints.end()) - actPoints.begin());
int lastRow = H - h + 1, lastCol = W - w + 1;
long long blockedArea = 0;
map<int, int> segmentStart;
int blockedRows = 0, sectionStart = 1;
int nextAct = 0;
auto findRange = [&](int b) {
int from = blockT[b], to = blockB[b];
auto it = segmentStart.lower_bound(blockT[b]);
if (it != segmentStart.begin()) {
auto it2 = prev(it);
from = max(from, it2->first+h);
}
if (it != segmentStart.end()) {
to = min(to, it->first-1);
}
return pair<int, int>{from, to};
};
auto changeSeg = [&](int from, int to, int sign) {
from = max(from, 1);
to = min(to, lastRow);
if (from <= to) blockedRows += (to-from+1)*sign;
};
for (int c : actPoints) {
if (c > lastCol) break;
blockedArea += (long long)blockedRows * (c - sectionStart);
sectionStart = c;
while (nextAct < (int)actI.size() && actI[nextAct].first.first == c) {
auto [pr, b] = actI[nextAct];
int action = pr.second;
if (action == -1) { // remove segment
segmentStart[blockT[b]]--;
if (segmentStart[blockT[b]] == 0) segmentStart.erase(blockT[b]);
auto [from, to] = findRange(b);
changeSeg(from, to, -1);
} else { // add segment
auto [from, to] = findRange(b);
changeSeg(from, to, +1);
segmentStart[blockT[b]]++;
}
++nextAct;
}
}
blockedArea += (long long)blockedRows * (lastCol+1 - sectionStart);
cout << (long long)lastRow*lastCol - blockedArea << endl;
return 0;
}
Submission Info
| Submission Time |
|
| Task |
F - Grid Clipping |
| User |
erekle |
| Language |
C++ IOI-Style(GNU++20) (GCC 14.2.0) |
| Score |
500 |
| Code Size |
2581 Byte |
| Status |
AC |
| Exec Time |
192 ms |
| Memory |
20468 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
0 ms |
1640 KiB |
| 00_sample_01.txt |
AC |
0 ms |
1640 KiB |
| 00_sample_02.txt |
AC |
0 ms |
1640 KiB |
| 00_sample_03.txt |
AC |
0 ms |
1640 KiB |
| 01_handmade_00.txt |
AC |
192 ms |
13044 KiB |
| 01_handmade_01.txt |
AC |
119 ms |
13044 KiB |
| 01_handmade_02.txt |
AC |
0 ms |
1640 KiB |
| 01_handmade_03.txt |
AC |
0 ms |
1640 KiB |
| 01_handmade_04.txt |
AC |
0 ms |
1640 KiB |
| 02_random_00.txt |
AC |
130 ms |
13040 KiB |
| 02_random_01.txt |
AC |
179 ms |
20468 KiB |
| 02_random_02.txt |
AC |
129 ms |
13044 KiB |
| 02_random_03.txt |
AC |
181 ms |
20468 KiB |
| 02_random_04.txt |
AC |
180 ms |
13044 KiB |
| 02_random_05.txt |
AC |
183 ms |
13044 KiB |
| 02_random_06.txt |
AC |
179 ms |
13044 KiB |
| 02_random_07.txt |
AC |
179 ms |
13044 KiB |
| 02_random_08.txt |
AC |
180 ms |
13044 KiB |
| 02_random_09.txt |
AC |
183 ms |
13044 KiB |
| 02_random_10.txt |
AC |
178 ms |
13144 KiB |
| 02_random_11.txt |
AC |
177 ms |
13044 KiB |
| 02_random_12.txt |
AC |
182 ms |
13044 KiB |
| 02_random_13.txt |
AC |
189 ms |
13040 KiB |
| 02_random_14.txt |
AC |
160 ms |
13044 KiB |
| 02_random_15.txt |
AC |
162 ms |
13044 KiB |
| 02_random_16.txt |
AC |
158 ms |
13040 KiB |
| 02_random_17.txt |
AC |
159 ms |
13044 KiB |
| 02_random_18.txt |
AC |
160 ms |
13044 KiB |