#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
using namespace std;
struct Node{
int val, lazy;
Node (int _val=0){
val=_val, lazy=0;
}
};
struct SegmentTree{
vector<Node> t;
int n, h;
void init(int _n){
n=_n;
h=32-__builtin_clz(n);
t.assign(2*n+1, Node());
}
void apply(int k, int val){
t[k].val+=val;
if (k<n) t[k].lazy+=val;
}
void build(int k){
while (k>1) k>>=1, t[k].val=min(t[k<<1].val, t[k<<1|1].val)+t[k].lazy;
}
void push(int k){
for (int s=h; s>0; --s){
int i=k>>s;
if (t[i].lazy){
apply(i<<1, t[i].lazy);
apply(i<<1|1, t[i].lazy);
t[i].lazy=0;
}
}
}
void update(int l, int r, int val){
--l;
l+=n; r+=n;
int l0=l, r0=r;
for (; l<r; l>>=1, r>>=1){
if (l&1) apply(l++, val);
if (r&1) apply(--r, val);
}
build(l0);
build(r0-1);
}
int get(int l, int r){
--l;
l+=n; r+=n;
push(l); push(r-1);
int ans=INT_MAX;
for (; l<r; l>>=1, r>>=1){
if (l&1) ans=min(ans, t[l++].val);
if (r&1) ans=min(ans, t[--r].val);
}
return ans;
}
} 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(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, q-mid+1)<=m;
}
}
}
if (check) l=mid+1;
else r=mid-1;
}
cout << r << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
19804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
19804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
20080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
20060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
21596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
35672 KB |
Output is correct |
2 |
Correct |
19 ms |
35676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
35676 KB |
Output is correct |
2 |
Correct |
23 ms |
35676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
20572 KB |
Output is correct |
2 |
Correct |
42 ms |
20580 KB |
Output is correct |
3 |
Correct |
40 ms |
20568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
177 ms |
22540 KB |
Output is correct |
2 |
Correct |
228 ms |
22756 KB |
Output is correct |
3 |
Correct |
166 ms |
22536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
303 ms |
37336 KB |
Output is correct |
2 |
Correct |
68 ms |
21672 KB |
Output is correct |
3 |
Correct |
132 ms |
37272 KB |
Output is correct |
4 |
Correct |
318 ms |
37320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
381 ms |
37472 KB |
Output is correct |
2 |
Correct |
378 ms |
37472 KB |
Output is correct |
3 |
Correct |
356 ms |
37488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
470 ms |
37672 KB |
Output is correct |
2 |
Correct |
556 ms |
37768 KB |
Output is correct |
3 |
Correct |
480 ms |
37640 KB |
Output is correct |
4 |
Correct |
500 ms |
37644 KB |
Output is correct |
5 |
Correct |
543 ms |
37632 KB |
Output is correct |
6 |
Correct |
389 ms |
37644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3262 ms |
50440 KB |
Output is correct |
2 |
Correct |
2017 ms |
36836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4913 ms |
61656 KB |
Output is correct |
2 |
Correct |
4989 ms |
62092 KB |
Output is correct |
3 |
Correct |
3530 ms |
62872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5048 ms |
64628 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |