#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define f first
#define s second
const int mxP = 4e5;
const int mxN = 1e6;
int n,m;
int segtree[4*mxN+1];
int laz[4*mxN+1];
int curr;
void build(int l = 0, int r = n-1, int idx = 0){
if (r+1<curr){
segtree[idx] = 2e9+1;
laz[idx] = 0;
return;
}
segtree[idx] = 0;
laz[idx] = 0;
if (l == r) return;
int m = (l+r)/2;
build(l,m,2*idx+1);
build(m+1,r,2*idx+2);
}
void upd(int tl, int tr, int v, int l = 0, int r = n-1, int idx = 0){
if (l > tr || r < tl || r+1<curr) return;
if (l >= tl && r <= tr){
laz[idx] += v;
return;
}
int m = (l+r)/2;
upd(tl,tr,v,l,m,2*idx+1);
upd(tl,tr,v,m+1,r,2*idx+2);
segtree[idx] = min(segtree[2*idx+1]+laz[2*idx+1],segtree[2*idx+2]+laz[2*idx+2]);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int b,p;
cin >> m >> n >> b >> p;
pii x[p];
pii y[p];
int c[p];
int x1,y1,x2,y2,c1;
for (int i =0; i < p; i++){
cin >> x1 >> y1 >> x2 >> y2 >> c1;
x1 -= 1;
y1 -= 1;
x2 -= 1;
y2 -= 1;
x[i] = {x1,x2};
y[i] = {y1,y2};
c[i] = c1;
}
int start = 0;
int end = min(n,m)+1;
bool w;
int best;
bool vis[p];
while (end - start > 1){
curr = (start+end)/2;
build();
memset(vis,0,sizeof(vis));
priority_queue<pii, vector<pii>, greater<pii>> queue;
for (int i = 0; i < p; i++){
queue.push({x[i].f,i});
queue.push({x[i].s+curr,i});
}
w = false;
while (queue.size() > 0){
pii cur = queue.top();
queue.pop();
if (cur.f >= m) break;
best = laz[0]+segtree[0];
if (best <= b && cur.f >= curr){
w = true;
break;
}
int val = c[cur.s];
if (vis[cur.s]) val *= -1;
else vis[cur.s] = 1;
upd(y[cur.s].f,min(n-1,y[cur.s].s+curr-1),val);
}
best = laz[0]+segtree[0];
if (best <= b) w = true;
if (w) start = curr;
else end = curr;
}
cout << start << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
18956 KB |
Output is correct |
2 |
Correct |
103 ms |
19036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
19032 KB |
Output is correct |
2 |
Correct |
34 ms |
19288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
2912 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
7564 KB |
Output is correct |
2 |
Correct |
214 ms |
8000 KB |
Output is correct |
3 |
Correct |
189 ms |
7984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
156 ms |
20212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
301 ms |
20468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
243 ms |
20592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4391 ms |
31524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5017 ms |
39944 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5019 ms |
43248 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |