#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=1e6+10;
int m, n, p, q;
Rect a[N], b[N];
vector<pair<int, pair<int, int>>> events[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;
for (int i=1; i<=n; ++i){
events[max(1ll, a[i].x1-mid+1)].push_back({a[i].z, {max(1ll, a[i].y1-mid+1), a[i].y2}});
events[a[i].x2+1].push_back({-a[i].z, {max(1ll, a[i].y1-mid+1), a[i].y2}});
}
bool check=0;
for (int i=1; i<=q+1; ++i){
for (auto &j:events[i]) st.update(1, 1, q, j.second.first, j.second.second, j.first);
if (i+mid-1<=p){
check|=st.get(1, 1, q, 1, q-mid+1)<=m;
}
events[i].clear();
events[i].shrink_to_fit();
}
if (check) l=mid+1;
else r=mid-1;
}
cout << r << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
101980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
101980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
102236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
102748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
148 ms |
108380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
351 ms |
164948 KB |
Output is correct |
2 |
Correct |
1247 ms |
164924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1167 ms |
164868 KB |
Output is correct |
2 |
Correct |
545 ms |
164700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
103432 KB |
Output is correct |
2 |
Correct |
71 ms |
103260 KB |
Output is correct |
3 |
Correct |
52 ms |
103308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
257 ms |
109988 KB |
Output is correct |
2 |
Correct |
309 ms |
109720 KB |
Output is correct |
3 |
Correct |
320 ms |
109732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
956 ms |
167136 KB |
Output is correct |
2 |
Incorrect |
36 ms |
110596 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1239 ms |
167744 KB |
Output is correct |
2 |
Correct |
1749 ms |
167312 KB |
Output is correct |
3 |
Correct |
799 ms |
167756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
986 ms |
168188 KB |
Output is correct |
2 |
Correct |
2009 ms |
167676 KB |
Output is correct |
3 |
Correct |
2029 ms |
167544 KB |
Output is correct |
4 |
Correct |
2139 ms |
167696 KB |
Output is correct |
5 |
Correct |
2114 ms |
167420 KB |
Output is correct |
6 |
Correct |
615 ms |
168184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5026 ms |
183272 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5024 ms |
193020 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5030 ms |
202020 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |