#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
const int len = 1e6+4;
const ll inf = 1e16;
int cost[len], n, m, bud, q;
vector<int> buck[len];
struct rectangle{
int x1, x2, y1, y2;
} rec[len];
struct node{
ll mn, lazy;
node(ll m = 0, ll l = 0){
mn = m;
lazy = l;
}
} tree[4*len];
void prop(int p, int l, int r){
tree[p].mn += tree[p].lazy;
if (l != r){
tree[2*p].lazy += tree[p].lazy;
tree[2*p+1].lazy += tree[p].lazy;
}
tree[p].lazy = 0;
}
void build(int p, int l, int r){
if (l == r)
return void(tree[p] = node());
int mid = (l+r)/2;
build(2*p, l, mid);
build(2*p+1, mid+1, r);
tree[p] = node();
}
void update(int p, int l, int r, int i, int j, int v){
prop(p, l, r);
if (r < i || j < l)
return;
if (i <= l && r <= j)
return void(tree[p].lazy += v);
int mid = (l+r)/2;
update(2*p, l, mid, i, j, v);
update(2*p+1, mid+1, r, i, j, v);
prop(2*p, l, mid), prop(2*p+1, mid+1, r);
tree[p].mn = min(tree[2*p].mn, tree[2*p+1].mn);
}
ll query(int p, int l, int r, int i, int j){
prop(p, l, r);
if (r < i || j < l)
return inf;
if (i <= l && r <= j)
return tree[p].mn;
int mid = (l+r)/2;
return min(query(2*p, l, mid, i, j), query(2*p+1, mid+1, r, i, j));
}
bool check(int k){
for (int i = 1; i <= m+1; i++)
buck[i].clear();
for (int i = 1; i <= q; i++){
int y1 = rec[i].y1, y2 = rec[i].y2;
buck[max(1, y1-k+1)].pb(i);
buck[y2+1].pb(-i);
}
build(1, 1, n);
for (int y = 1; y <= m-k+1; y++){
for (int j = 0; j < buck[y].size(); j++){
int i = abs(buck[y][j]);
int x1 = rec[i].x1, x2 = rec[i].x2;
if (buck[y][j] > 0)
update(1, 1, n, max(1, x1-k+1), x2, cost[i]);
else
update(1, 1, n, max(1, x1-k+1), x2, -cost[i]);
}
if (y != 1 || buck[y].empty())
continue;
if (query(1, 1, n, 1, n-k+1) <= bud)
return true;
}
return false;
}
int bs(){
int l = 1, r = min(n, m), ans = 0;
while (l <= r){
int mid = (l+r)/2;
if (check(mid))
ans = mid, l = mid+1;
else
r = mid-1;
}
return ans;
}
int main(){
scanf("%d %d %d %d", &n, &m, &bud, &q);
for (int i = 1; i <= q; i++)
scanf("%d %d %d %d %d", &rec[i].x1, &rec[i].y1, &rec[i].x2, &rec[i].y2, &cost[i]);
printf("%d\n", bs());
return 0;
}
Compilation message
pyramid_base.cpp: In function 'bool check(int)':
pyramid_base.cpp:83:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for (int j = 0; j < buck[y].size(); j++){
| ~~^~~~~~~~~~~~~~~~
pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:117:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
117 | scanf("%d %d %d %d", &n, &m, &bud, &q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pyramid_base.cpp:119:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
119 | scanf("%d %d %d %d %d", &rec[i].x1, &rec[i].y1, &rec[i].x2, &rec[i].y2, &cost[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
53 ms |
86520 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
58 ms |
86392 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
55 ms |
86488 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
86648 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
84 ms |
87032 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
331 ms |
86952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
294 ms |
87032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
83 ms |
86776 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
357 ms |
89292 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
923 ms |
92280 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1249 ms |
95008 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1042 ms |
93304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5046 ms |
119076 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5044 ms |
125488 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5039 ms |
130976 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |