#include<bits/stdc++.h>
using namespace std;
const int maxn = 4e5+5, maxp = 1e6+5, inf = 1e9;
int n, m, p, b;
struct R {
int x1, y1, x2, y2, c;
R() { x1 = y1 = x2 = y2 = c = 0; }
} obs[maxn];
struct N {
int v, l;
} stree[4*maxp];
void push(int i) {
if(stree[i].l != 0) {
stree[i<<1].v += stree[i].l; stree[i<<1|1].v += stree[i].l;
stree[i<<1].l += stree[i].l; stree[i<<1|1].l += stree[i].l;
stree[i].l = 0;
}
}
void update(int lq, int rq, int val, int i = 1, int l = 1, int r = maxp) {
if(lq <= l && r <= rq) {
stree[i].v += val, stree[i].l += val;
return;
}
push(i);
int mid = (l+r)/2;
if(lq <= mid) update(lq, rq, val, i<<1, l, mid);
if(rq >= mid+1) update(lq, rq, val, i<<1|1, mid+1, r);
stree[i].v = min(stree[i<<1].v, stree[i<<1|1].v);
}
int query(int lq, int rq, int i = 1, int l = 1, int r = maxp) {
if(lq <= l && r <= rq) return stree[i].v;
push(i);
int mid = (l+r)/2, ret = inf;
if(lq <= mid) ret = min(ret, query(lq, rq, i<<1, l, mid));
if(rq >= mid+1) ret = min(ret, query(lq, rq, i<<1|1, mid+1, r));
return ret;
}
vector<pair<pair<int, int>, pair<int, int>>> evs;
bool check(int x) {
bool ret = false;
evs.clear();
for(int i = 1; i <= p; i++) {
evs.push_back({{max(1, obs[i].x1-x+1), obs[i].c}, {max(1, obs[i].y1-x+1), obs[i].y2}});
evs.push_back({{obs[i].x2+1, -obs[i].c}, {max(1, obs[i].y1-x+1), obs[i].y2}});
}
sort(evs.begin(), evs.end());
for(int i = 0; i < evs.size(); i++) {
update(evs[i].second.first, evs[i].second.second, evs[i].first.second);
if(i >= evs.size()-1 || evs[i].first.first != evs[i+1].first.first) {
if(evs[i].first.first+x-1 <= m) ret |= (query(1, n-x+1) <= b);
}
}
return ret;
}
int bsearch(int l, int r) {
int ret = 0;
while(l <= r) {
int mid = (l+r)/2;
if(check(mid)) l = mid+1, ret = mid;
else r = mid-1;
}
return ret;
}
int main() {
cin >> m >> n >> b >> p; // m columns, n rows
for(int i = 1; i <= p; i++) cin >> obs[i].x1 >> obs[i].y1 >> obs[i].x2 >> obs[i].y2 >> obs[i].c;
cout << bsearch(1, min(m, n)) << "\n";
}
Compilation message
pyramid_base.cpp: In function 'bool check(int)':
pyramid_base.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i = 0; i < evs.size(); i++) {
| ~~^~~~~~~~~~~~
pyramid_base.cpp:52:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | if(i >= evs.size()-1 || evs[i].first.first != evs[i+1].first.first) {
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
12636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
12632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
18780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
24924 KB |
Output is correct |
2 |
Correct |
20 ms |
25180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
25180 KB |
Output is correct |
2 |
Correct |
15 ms |
25180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
13012 KB |
Output is correct |
2 |
Correct |
52 ms |
10968 KB |
Output is correct |
3 |
Correct |
47 ms |
15060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
198 ms |
16336 KB |
Output is correct |
2 |
Correct |
232 ms |
20176 KB |
Output is correct |
3 |
Correct |
194 ms |
19668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
321 ms |
26564 KB |
Output is correct |
2 |
Correct |
92 ms |
15824 KB |
Output is correct |
3 |
Correct |
134 ms |
26308 KB |
Output is correct |
4 |
Correct |
418 ms |
26568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
424 ms |
27076 KB |
Output is correct |
2 |
Correct |
481 ms |
26832 KB |
Output is correct |
3 |
Correct |
314 ms |
26892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
436 ms |
27076 KB |
Output is correct |
2 |
Correct |
678 ms |
27080 KB |
Output is correct |
3 |
Correct |
604 ms |
27080 KB |
Output is correct |
4 |
Correct |
622 ms |
27088 KB |
Output is correct |
5 |
Correct |
622 ms |
27076 KB |
Output is correct |
6 |
Correct |
354 ms |
27080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4257 ms |
37992 KB |
Output is correct |
2 |
Correct |
2209 ms |
26800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5042 ms |
43492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5064 ms |
50600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |