#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
using namespace std;
// #define int long long
struct Node{
int val, lazy;
Node (int _val=0){
val=_val, lazy=0;
}
void merge(const Node &tl, const Node &tr){
val=min(tl.val, tr.val);
}
};
struct SegmentTree{
vector<Node> t;
int n;
void init(int _n){
n=_n;
t.assign(4*n+1, Node());
}
void apply(int k, int val){
t[k].val+=val;
t[k].lazy+=val;
}
void push(int k){
if (t[k].lazy){
apply(k<<1, t[k].lazy);
apply(k<<1|1, t[k].lazy);
t[k].lazy=0;
}
}
void update(int k, int l, int r, int L, int R, int val){
if (r<L || R<l) return;
if (L<=l && r<=R){
apply(k, val);
return;
}
push(k);
int mid=(l+r)>>1;
update(k<<1, l, mid, L, R, val);
update(k<<1|1, mid+1, r, L, R, val);
t[k].merge(t[k<<1], t[k<<1|1]);
}
int get(int k, int l, int r, int L, int R){
if (r<L || R<l) return 1e18;
if (L<=l && r<=R) return t[k].val;
push(k);
int mid=(l+r)>>1;
return min(get(k<<1, l, mid, L, R), get(k<<1|1, mid+1, r, L, R));
}
} st;
struct Rect{
int x1, y1, x2, y2, z;
Rect(){ x1=0, y1=0, x2=0, y2=0, z=0; }
};
const int N=5e5+10;
int m, n, p, q;
Rect a[N], b[N];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> p >> q >> m >> n;
st.init(q);
for (int i=1; i<=n; ++i) cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2 >> a[i].z;
int l=1, r=min(p, q);
while (l<=r){
int mid=(l+r)>>1;
vector<pair<pair<int, int>, pair<int, int>>> events;
for (int i=1; i<=n; ++i){
events.push_back({{max(1, a[i].x1-mid+1), a[i].z}, {max(1, a[i].y1-mid+1), a[i].y2}});
events.push_back({{a[i].x2+1, -a[i].z}, {max(1, a[i].y1-mid+1), a[i].y2}});
}
sort(events.begin(), events.end());
bool check=0;
for (int i=0; i<(int)events.size(); ++i){
st.update(1, 1, q, events[i].second.first, events[i].second.second, events[i].first.second);
if (i==(int)events.size()-1 || events[i].first.first!=events[i+1].first.first){
if (events[i].first.first+mid-1<=p){
check|=st.get(1, 1, q, 1, q-mid+1)<=m;
}
}
}
if (check) l=mid+1;
else r=mid-1;
}
cout << r << '\n';
return 0;
}
Compilation message
pyramid_base.cpp: In member function 'int SegmentTree::get(int, int, int, int, int)':
pyramid_base.cpp:50:30: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
50 | if (r<L || R<l) return 1e18;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
19804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
19800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
20056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
20316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
51292 KB |
Output is correct |
2 |
Correct |
26 ms |
51284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
51288 KB |
Output is correct |
2 |
Correct |
21 ms |
51288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
20768 KB |
Output is correct |
2 |
Correct |
56 ms |
20768 KB |
Output is correct |
3 |
Correct |
49 ms |
20772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
220 ms |
24072 KB |
Output is correct |
2 |
Correct |
242 ms |
24088 KB |
Output is correct |
3 |
Correct |
207 ms |
24140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
358 ms |
52976 KB |
Output is correct |
2 |
Correct |
64 ms |
21648 KB |
Output is correct |
3 |
Correct |
134 ms |
52892 KB |
Output is correct |
4 |
Correct |
400 ms |
52988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
465 ms |
53132 KB |
Output is correct |
2 |
Correct |
458 ms |
53144 KB |
Output is correct |
3 |
Correct |
365 ms |
53136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
478 ms |
53288 KB |
Output is correct |
2 |
Correct |
639 ms |
53296 KB |
Output is correct |
3 |
Correct |
634 ms |
53512 KB |
Output is correct |
4 |
Correct |
646 ms |
53284 KB |
Output is correct |
5 |
Correct |
662 ms |
53488 KB |
Output is correct |
6 |
Correct |
461 ms |
53480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4407 ms |
66512 KB |
Output is correct |
2 |
Correct |
1874 ms |
38528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5058 ms |
77316 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5050 ms |
80384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |