#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 0x3fffffff;
template<class T, class U> bool chmin(T& a, const U& b){ if(a > b){ a = b; return 1; } return 0; }
#define rep(b) for(ll i = 0; i < b; i++)
#define each(i,a) for(auto&& i : a)
#define all(a) begin(a), end(a)
ll seg[2000000], lazy[2000000];
struct SegTree{
int n;
SegTree(int n): n(n){}
inline ll get() const {
return seg[1];
}
inline void add(int l, int r, int val){
if(l < 0) l = 0;
if(r > n) r = n;
l += n;
r += n;
int L = l, R = r;
for(; L < R; L /= 2, R /= 2){
if(L & 1){
seg[L] += val;
lazy[L++] += val;
}
if(R & 1){
seg[--R] += val;
lazy[R] += val;
}
}
r--;
while(l /= 2) seg[l] = min(seg[l * 2], seg[l * 2 | 1]) + lazy[l];
while(r /= 2) seg[r] = min(seg[r * 2], seg[r * 2 | 1]) + lazy[r];
}
inline void clear(int l, int r){
if(l < 0) l = 0;
if(r > n) r = n;
l += n;
r += n;
int L = l, R = r;
for(; L < R; L /= 2, R /= 2){
if(L & 1){
seg[L] = 0;
lazy[L++] = 0;
}
if(R & 1){
seg[--R] = 0;
lazy[R] = 0;
}
}
r--;
while(l /= 2) seg[l] = 0;
while(r /= 2) seg[r] = 0;
}
};
int main(){
int m, n, b, p;
scanf("%d %d %d %d", &m, &n, &b, &p);
using tuplis = array<int, 4>;
vector<tuplis> in, out;
rep(p){
int x1, y1, x2, y2, c;
scanf("%d %d %d %d %d", &x1, &y1, &x2, &y2, &c);
x1--; y1--;
in.push_back({x1, y1, y2, c});
out.push_back({x2, y1, y2, -c});
}
sort(all(in));
sort(all(out));
in.push_back({INF, 0, 0, 0});
out.push_back({INF, 0, 0, 0});
auto check = [&](int x) -> bool {
x--;
SegTree seg(n - x);
int i1 = 0, i2 = 0, at = 0;
bool ans = 0;
while(at < m - x){
while(in[i1][0] - x <= at){
seg.add(in[i1][1] - x, in[i1][2], in[i1][3]);
i1++;
}
while(out[i2][0] <= at){
seg.add(out[i2][1] - x, out[i2][2], out[i2][3]);
i2++;
}
if(seg.get() <= b){
ans = 1;
break;
}
at = min(in[i1][0] - x, out[i2][0]);
}
for(; i2 < i1; i2++) seg.clear(out[i2][1] - x, out[i2][2]);
return ans;
};
int ok = 0, ng = min(n, m) + 1;
while(ng - ok > 1){
ll cen = (ok + ng) / 2;
if(check(cen)) ok = cen;
else ng = cen;
}
cout << ok << endl;
}
Compilation message
pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d", &m, &n, &b, &p);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pyramid_base.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d %d", &x1, &y1, &x2, &y2, &c);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
3200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
8808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
28664 KB |
Output is correct |
2 |
Correct |
19 ms |
11776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
768 KB |
Output is correct |
2 |
Correct |
33 ms |
896 KB |
Output is correct |
3 |
Incorrect |
34 ms |
1024 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
3444 KB |
Output is correct |
2 |
Correct |
139 ms |
4084 KB |
Output is correct |
3 |
Correct |
125 ms |
4084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
16884 KB |
Output is correct |
2 |
Correct |
23 ms |
1788 KB |
Output is correct |
3 |
Correct |
154 ms |
32960 KB |
Output is correct |
4 |
Incorrect |
227 ms |
31080 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
333 ms |
24812 KB |
Output is correct |
2 |
Correct |
473 ms |
33388 KB |
Output is correct |
3 |
Correct |
177 ms |
17780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
285 ms |
17200 KB |
Output is correct |
2 |
Correct |
658 ms |
33644 KB |
Output is correct |
3 |
Incorrect |
640 ms |
33644 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3257 ms |
37916 KB |
Output is correct |
2 |
Correct |
317 ms |
9420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4992 ms |
41264 KB |
Output is correct |
2 |
Incorrect |
4104 ms |
41904 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5093 ms |
44284 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |