#include <bits/stdc++.h>
using namespace std;
#define FORN(i, a, b) for(int i=a; i<=b; ++i)
#define FORD(i, a, b) for(int i=a; i>=b; --i)
#define REPN(i, a, b) for(int i=a; i <b; ++i)
#define REPD(i, a, b) for(int i=(int)a-1; i>=b; --i)
const int maxR = 4*1e5 +10;
const int maxN = 1e6 +10;
const int INF = 1e9 +7;
int M, N, B, P;
typedef tuple<int, int, int> i3;
vector< i3 > open[maxN], close[maxN];
struct Rectangle {
int x1, y1, x2, y2, cost;
Rectangle(){};
Rectangle(int x1, int y1, int x2, int y2): x1(x1), y1(y1), x2(x2), y2(y2) {};
void expand(int d, int id = 0) {
open[max(1, x1-d)].push_back({max(1, y1-d), y2, cost});
close[x2].push_back({max(1, y1-d), y2, cost});
open[x2+1].push_back({1, P+1, 0});
}
friend istream & operator >> (istream &is, Rectangle &T) {
is >> T.x1 >> T.y1 >> T.x2 >> T.y2 >> T.cost;
return is;
}
} rec[maxR];
namespace subtask2 {
#define ii pair<int, int>
int a[maxN];
int it[4*maxN], t[4*maxN];
void lazy(int x, int l, int r) {
it[x] += t[x];
if (l != r) {
t[2*x] += t[x];
t[2*x+1] += t[x];
}
t[x] = 0;
}
void update(int x, int l, int r, int i, int j, int cost) {
lazy(x, l, r);
if (a[r] < i || j < a[l]) return;
if (i <= a[l] && a[r] <= j) {
t[x] = cost;
lazy(x, l, r);
return;
}
int m = l+r >> 1;
update(2*x, l, m, i, j, cost);
update(2*x+1, m+1, r, i, j, cost);
it[x] = min(it[2*x], it[2*x+1]);
}
int query(int x, int l, int r, int i, int j) {
lazy(x, l, r);
if (a[r] < i || j < a[l]) return INF;
if (i <= a[l] && a[r] <= j) return it[x];
int m = l+r >> 1;
return min(query(2*x, l, m, i, j), query(2*x+1, m+1, r, i, j));
}
bool ok(int d) {
FORN(i, 1, P) rec[i].expand(d -1, 1);
int result = INF;
open[1].push_back({1, N-d+1, 0});
FORN(i, 0, M) {
if (open[i].size()) {
for(auto ss: open[i]) {
int y1, y2, cost;
tie(y1, y2, cost) = ss;
update(1, 1, P+1, y1, y2, cost);
}
if (i <= M-d+1) result = min(result, query(1, 1, P+1, 1, N-d+1));
}
if (close[i].size()) {
for(auto ss: close[i]) {
int y1, y2, cost;
tie(y1, y2, cost) = ss;
update(1, 1, P+1, y1, y2, -cost);
}
}
}
FORN(i, 1, M) open[i].clear(), close[i].clear();
return (result <= B);
}
void run() {
FORN(i, 1, P) a[i] = rec[i].y2 + 1;
a[P+1] = 1;
sort(a+1, a+P+2);
int low = 0, high = min(M, N), result = 0;
while (low <= high) {
int mid = low + high >> 1;
if (ok(mid)) {
result = mid;
low = mid+1;
} else high = mid-1;
}
cout << result << '\n';
}
}
namespace subtask3 {
int result = 0;
int mx[4*maxN], le[4*maxN], ri[4*maxN], cnt[4*maxN];
void lazy(int x, int l, int r) {
int m = l+r >> 1;
if (l<r) {
mx[x] = max(max(mx[2*x], mx[2*x+1]), ri[2*x] + le[2*x+1]);
le[x] = (le[2*x] >= m-l+1 ? le[2*x] + le[2*x+1] : le[2*x]);
ri[x] = (ri[2*x+1] >= r-m ? ri[2*x+1] + ri[2*x] : ri[2*x+1]);
} else mx[x] = le[x] = ri[x] = 1;
}
void update(int x, int l, int r, int i, int j, int cost) {
if (j < l || r < i) return;
if (i <= l && r <= j) {
cnt[x] += cost;
if (cnt[x]) mx[x] = le[x] = ri[x] = 0;
else lazy(x, l, r);
return;
}
int m = l+r >> 1;
update(2*x, l, m, i, j, cost);
update(2*x+1, m+1, r, i, j, cost);
if (cnt[x] == 0) lazy(x, l, r);
}
void update(int r) {
for(auto ss: open[r]) {
int y1, y2, cost;
tie(y1, y2, cost) = ss;
update(1, 1, N, y1, y2, 1);
close[rec[cost].x2].push_back({y1, y2, cost});
}
}
void build(int x, int l, int r) {
mx[x] = le[x] = ri[x] = r-l+1;
if (l == r) return;
int m = l+r >> 1;
build(2*x, l, m);
build(2*x+1, m+1, r);
}
void run() {
build(1, 1, N);
FORN(i, 1, P) open[rec[i].x1].push_back({rec[i].y1, rec[i].y2, i});
int ri = 0;
FORN(i, 1, M) {
ri = max(ri, i);
while (ri <= M && mx[1] >= (ri-i+1)) {
update(ri);
ri ++;
}
result = max(result, ri-i);
for(auto ss: close[i]) {
int y1, y2, cost;
tie(y1, y2, cost) = ss;
update(1, 1, N, y1, y2, -1);
}
}
cout << result << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0);
cin >> M >> N >> B >> P;
FORN(i, 1, P) cin >> rec[i];
if (P <= 3e4) subtask2::run();
else subtask3::run();
return 0;
}
Compilation message
pyramid_base.cpp: In function 'void subtask2::update(int, int, int, int, int, int)':
pyramid_base.cpp:47:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l+r >> 1;
~^~
pyramid_base.cpp: In function 'int subtask2::query(int, int, int, int, int)':
pyramid_base.cpp:56:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l+r >> 1;
~^~
pyramid_base.cpp: In function 'void subtask2::run()':
pyramid_base.cpp:89:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = low + high >> 1;
~~~~^~~~~~
pyramid_base.cpp: In function 'void subtask3::lazy(int, int, int)':
pyramid_base.cpp:103:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l+r >> 1;
~^~
pyramid_base.cpp: In function 'void subtask3::update(int, int, int, int, int, int)':
pyramid_base.cpp:118:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l+r >> 1;
~^~
pyramid_base.cpp: In function 'void subtask3::build(int, int, int)':
pyramid_base.cpp:134:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l+r >> 1;
~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
47352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
47352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
47480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
47612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
47732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
306 ms |
47736 KB |
Output is correct |
2 |
Correct |
312 ms |
47992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
368 ms |
48056 KB |
Output is correct |
2 |
Correct |
308 ms |
47736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
48012 KB |
Output is correct |
2 |
Correct |
140 ms |
48184 KB |
Output is correct |
3 |
Correct |
133 ms |
48292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
545 ms |
50752 KB |
Output is correct |
2 |
Correct |
571 ms |
51256 KB |
Output is correct |
3 |
Correct |
478 ms |
52020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1039 ms |
53956 KB |
Output is correct |
2 |
Correct |
378 ms |
53368 KB |
Output is correct |
3 |
Correct |
245 ms |
49844 KB |
Output is correct |
4 |
Correct |
1195 ms |
57604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1358 ms |
56876 KB |
Output is correct |
2 |
Correct |
1351 ms |
61236 KB |
Output is correct |
3 |
Correct |
1016 ms |
51756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1361 ms |
55080 KB |
Output is correct |
2 |
Correct |
1701 ms |
62560 KB |
Output is correct |
3 |
Correct |
1672 ms |
62256 KB |
Output is correct |
4 |
Correct |
1696 ms |
62580 KB |
Output is correct |
5 |
Correct |
1667 ms |
62768 KB |
Output is correct |
6 |
Correct |
1114 ms |
51380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
729 ms |
95536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
963 ms |
102008 KB |
Output is correct |
2 |
Correct |
516 ms |
94848 KB |
Output is correct |
3 |
Correct |
782 ms |
105052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1198 ms |
107280 KB |
Output is correct |
2 |
Correct |
561 ms |
99376 KB |
Output is correct |
3 |
Correct |
569 ms |
99388 KB |
Output is correct |
4 |
Correct |
651 ms |
111024 KB |
Output is correct |
5 |
Incorrect |
942 ms |
113112 KB |
Output isn't correct |