#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) {
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+2);
l++;
}
if (~s) st.upd(y1[s]-sz+1, y2[s]+1, -c[s], 1, 1, n-sz+2);
if (st.st[1] <= b) return 1;
}
return 0;
}
struct max_zeros {
int st[1<<21], ans[1<<21], pfx[1<<21], sfx[1<<21];
void build(int t, int l, int r) {
if (r - l > 1) {
int m = l+r>>1;
build(t*2, l, m);
build(t*2+1, m, r);
}
ans[t] = pfx[t] = sfx[t] = r-l;
}
void pull(int t, int l, int r) {
int m = l+r>>1;
pfx[t] = pfx[t*2] + (pfx[t*2] == m-l ? pfx[t*2+1] : 0);
sfx[t] = sfx[t*2+1] + (sfx[t*2+1] == r-m ? sfx[t*2] : 0);
ans[t] = max({ans[t*2], ans[t*2+1], sfx[t*2] + pfx[t*2+1]});
}
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;
if (st[t] <= 0) {
if (r-l>1) pull(t, l, r);
else ans[t] = pfx[t] = sfx[t] = 1;
}
else ans[t] = pfx[t] = sfx[t] = 0;
return;
}
int m = l+r>>1;
upd(ul, ur, v, t*2, l, m);
upd(ul, ur, v, t*2+1, m, r);
if (st[t] <= 0) pull(t, l, r);
}
};
void sub3() {
int ans = 0, l=0;
max_zeros st{};
st.build(1, 1, n+1);
for (auto [x, s]: rht) {
if (~s) st.upd(y1[s], y2[s]+1, -1, 1, 1, n+1);
while (l < lft.size() && st.ans[1] >= lft[l].first-x-1) {
ans = max(ans, lft[l].first-x-1);
st.upd(y1[lft[l].second], y2[lft[l].second]+1, 1, 1, 1, n+1);
l++;
}
}
cout << ans;
}
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());
if (b == 0) {
sub3();
return 0;
}
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:40: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]
40 | if (l == lft.size()-1) return 0;
| ~~^~~~~~~~~~~~~~~
pyramid_base.cpp: In member function 'void max_zeros::build(int, int, int)':
pyramid_base.cpp:54:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
54 | int m = l+r>>1;
| ~^~
pyramid_base.cpp: In member function 'void max_zeros::pull(int, int, int)':
pyramid_base.cpp:61:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
61 | int m = l+r>>1;
| ~^~
pyramid_base.cpp: In member function 'void max_zeros::upd(int, int, int, int, int, int)':
pyramid_base.cpp:77:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
77 | int m = l+r>>1;
| ~^~
pyramid_base.cpp: In function 'void sub3()':
pyramid_base.cpp:88:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
88 | for (auto [x, s]: rht) {
| ^
pyramid_base.cpp:90:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | while (l < lft.size() && st.ans[1] >= lft[l].first-x-1) {
| ~~^~~~~~~~~~~~
pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:118:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
118 | mid = lo+hi>>1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
33100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
33124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
33100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
33100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
33100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
33220 KB |
Output is correct |
2 |
Correct |
31 ms |
33188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
33100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
16972 KB |
Output is correct |
2 |
Correct |
76 ms |
17028 KB |
Output is correct |
3 |
Correct |
76 ms |
17016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
17348 KB |
Output is correct |
2 |
Correct |
289 ms |
17396 KB |
Output is correct |
3 |
Correct |
232 ms |
17408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
183 ms |
17684 KB |
Output is correct |
2 |
Correct |
34 ms |
17608 KB |
Output is correct |
3 |
Correct |
139 ms |
17684 KB |
Output is correct |
4 |
Correct |
340 ms |
17684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
318 ms |
17860 KB |
Output is correct |
2 |
Correct |
719 ms |
17940 KB |
Output is correct |
3 |
Correct |
114 ms |
17860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
232 ms |
17928 KB |
Output is correct |
2 |
Correct |
907 ms |
18112 KB |
Output is correct |
3 |
Correct |
895 ms |
18024 KB |
Output is correct |
4 |
Correct |
919 ms |
18140 KB |
Output is correct |
5 |
Correct |
913 ms |
18120 KB |
Output is correct |
6 |
Correct |
87 ms |
17984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
652 ms |
40424 KB |
Output is correct |
2 |
Correct |
463 ms |
40476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
821 ms |
43984 KB |
Output is correct |
2 |
Correct |
916 ms |
43924 KB |
Output is correct |
3 |
Correct |
705 ms |
43924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1049 ms |
47336 KB |
Output is correct |
2 |
Correct |
1384 ms |
47384 KB |
Output is correct |
3 |
Correct |
1406 ms |
47376 KB |
Output is correct |
4 |
Correct |
1278 ms |
47396 KB |
Output is correct |
5 |
Correct |
1038 ms |
47372 KB |
Output is correct |