#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e6;
const int MAXP = 4e5;
const ll INF = 1e18;
struct Rect
{
int x1, y1, x2, y2, w;
};
struct Line
{
int x, y1, y2, w;
bool operator < (const Line &p) const { return x<p.x; }
};
int N, M, P;
ll B;
Rect A[MAXP+10];
struct SEG
{
ll tree[MAXN*4+10], lazy[MAXN*4+10];
void init()
{
memset(tree, 0, sizeof(tree));
memset(lazy, 0, sizeof(lazy));
}
void busy(int node, int tl, int tr)
{
tree[node]+=lazy[node];
if(tl!=tr) lazy[node*2]+=lazy[node], lazy[node*2+1]+=lazy[node];
lazy[node]=0;
}
void update(int node, int tl, int tr, int l, int r, ll v)
{
busy(node, tl, tr);
if(r<tl || tr<l) return;
if(l<=tl && tr<=r)
{
lazy[node]+=v;
busy(node, tl, tr);
return;
}
int mid=tl+tr>>1;
update(node*2, tl, mid, l, r, v);
update(node*2+1, mid+1, tr, l, r, v);
tree[node]=min(tree[node*2], tree[node*2+1]);
}
}seg;
bool solve(int d)
{
int i, j;
vector<Line> V;
ll val=INF;
for(i=1; i<=P; i++)
{
V.push_back({A[i].x1, A[i].y1, A[i].y2+d-1, A[i].w});
V.push_back({A[i].x2+d, A[i].y1, A[i].y2+d-1, -A[i].w});
}
sort(V.begin(), V.end());
seg.init();
for(i=0; i<V.size();)
{
int x=V[i].x;
seg.busy(1, d, N);
if(d<=x-1 && x-1<=M) val=min(val, seg.tree[1]);
if(x>M) break;
for(; i<V.size() && V[i].x==x; i++)
{
seg.update(1, d, N, V[i].y1, V[i].y2, V[i].w);
}
}
if(val<=B) return true;
return false;
}
int main()
{
int i, j;
scanf("%d%d%lld%d", &M, &N, &B, &P);
for(i=1; i<=P; i++) scanf("%d%d%d%d%d", &A[i].x1, &A[i].y1, &A[i].x2, &A[i].y2, &A[i].w);
int lo=0, hi=min(N, M)+1;
while(lo+1<hi)
{
int mid=lo+hi>>1;
if(solve(mid)) lo=mid;
else hi=mid;
}
printf("%d\n", lo);
}
Compilation message
pyramid_base.cpp: In member function 'void SEG::update(int, int, int, int, int, ll)':
pyramid_base.cpp:51:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
pyramid_base.cpp: In function 'bool solve(int)':
pyramid_base.cpp:71:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0; i<V.size();)
~^~~~~~~~~
pyramid_base.cpp:77:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; i<V.size() && V[i].x==x; i++)
~^~~~~~~~~
pyramid_base.cpp:60:9: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:96:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=lo+hi>>1;
~~^~~
pyramid_base.cpp:88:9: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
pyramid_base.cpp:90:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%lld%d", &M, &N, &B, &P);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pyramid_base.cpp:91:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=P; i++) scanf("%d%d%d%d%d", &A[i].x1, &A[i].y1, &A[i].x2, &A[i].y2, &A[i].w);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
62968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
62976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
62968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
62968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
164 ms |
63096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
188 ms |
63104 KB |
Output is correct |
2 |
Correct |
195 ms |
63104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
223 ms |
63104 KB |
Output is correct |
2 |
Correct |
191 ms |
63076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
63492 KB |
Output is correct |
2 |
Correct |
180 ms |
63508 KB |
Output is correct |
3 |
Correct |
176 ms |
63992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
353 ms |
64312 KB |
Output is correct |
2 |
Correct |
450 ms |
64384 KB |
Output is correct |
3 |
Correct |
400 ms |
64280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
472 ms |
65176 KB |
Output is correct |
2 |
Correct |
123 ms |
65052 KB |
Output is correct |
3 |
Correct |
254 ms |
65036 KB |
Output is correct |
4 |
Correct |
830 ms |
65148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
703 ms |
65340 KB |
Output is correct |
2 |
Correct |
924 ms |
65412 KB |
Output is correct |
3 |
Correct |
359 ms |
65436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
528 ms |
65540 KB |
Output is correct |
2 |
Correct |
1268 ms |
65780 KB |
Output is correct |
3 |
Correct |
1242 ms |
65640 KB |
Output is correct |
4 |
Correct |
1249 ms |
65652 KB |
Output is correct |
5 |
Incorrect |
1235 ms |
65656 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5071 ms |
81520 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5090 ms |
94832 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5085 ms |
99840 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |