#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> pii;
const int mxP = 4e5;
int m,n,b,p,x1[mxP],y1[mxP],x2[mxP],y2[mxP],c[mxP];
vector<pii> lft, rht;
struct range_add {
int st[1<<21], lz[1<<21];
void push(int t) {
st[t*2] += lz[t];
st[t*2+1] += lz[t];
lz[t*2] += lz[t];
lz[t*2+1] += lz[t];
lz[t] = 0;
}
void upd(int ul, int ur, int v, int t, int l, int r) {
if (ur <= l || r <= ul) return;
if (ul <= l && r <= ur) {
st[t] += v;
lz[t] += v;
return;
}
int m = l+r>>1;
push(t);
upd(ul, ur, v, t*2, l, m);
upd(ul, ur, v, t*2+1, m, r);
st[t] = min(st[t*2], st[t*2+1]);
}
};
bool can_do(int sz) {
range_add st{};
int l = 0;
for (auto [x, s]: rht) {
if (~s) st.upd(y1[s]-sz+1, y2[s]+1, -c[s], 1, 1, n-sz+1);
while (lft[l].first - x <= sz) {
if (l == lft.size()-1) return 0;
st.upd(y1[lft[l].second]-sz+1, y2[lft[l].second]+1, c[lft[l].second], 1, 1, n-sz+1);
l++;
}
if (st.st[1] <= b) return 1;
}
return 0;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> m >> n >> b >> p;
lft.push_back({m+1, -1});
rht.push_back({0, -1});
for (int i = 0; i < p; ++i) {
cin >> x1[i] >> y1[i] >> x2[i] >> y2[i] >> c[i];
lft.push_back({x1[i], i});
rht.push_back({x2[i], i});
}
sort(lft.begin(), lft.end());
sort(rht.begin(), rht.end());
int lo = 1, hi = min(m,n)+1, mid;
while (lo != hi) {
mid = lo+hi>>1;
if (can_do(mid)) lo = mid+1;
else hi = mid;
}
cout << lo-1;
}
Compilation message
pyramid_base.cpp: In member function 'void range_add::upd(int, int, int, int, int, int)':
pyramid_base.cpp:27:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
27 | int m = l+r>>1;
| ~^~
pyramid_base.cpp: In function 'bool can_do(int)':
pyramid_base.cpp:38:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
38 | for (auto [x, s]: rht) {
| ^
pyramid_base.cpp:41:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | if (l == lft.size()-1) return 0;
| ~~^~~~~~~~~~~~~~~
pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:65:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
65 | mid = lo+hi>>1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
16716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
16756 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
16764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
16716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
16716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
16776 KB |
Output is correct |
2 |
Correct |
74 ms |
16808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
16784 KB |
Output is correct |
2 |
Correct |
54 ms |
16716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
17036 KB |
Output is correct |
2 |
Correct |
79 ms |
17132 KB |
Output is correct |
3 |
Correct |
74 ms |
17100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
17376 KB |
Output is correct |
2 |
Incorrect |
277 ms |
17808 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
193 ms |
17688 KB |
Output is correct |
2 |
Correct |
35 ms |
18112 KB |
Output is correct |
3 |
Correct |
138 ms |
18000 KB |
Output is correct |
4 |
Incorrect |
381 ms |
18320 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
329 ms |
17856 KB |
Output is correct |
2 |
Correct |
779 ms |
18588 KB |
Output is correct |
3 |
Incorrect |
114 ms |
18644 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
243 ms |
18028 KB |
Output is correct |
2 |
Incorrect |
965 ms |
18900 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5074 ms |
23956 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5075 ms |
27492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5094 ms |
31108 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |