This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned;
using ll = long long;
const int INF = 0x3fffffff;
template<class T, class U> bool chmin(T& a, const U& b){ if(a > b){ a = b; return 1; } return 0; }
#define rep(b) for(ll i = 0; i < b; i++)
#define each(i,a) for(auto&& i : a)
#define all(a) begin(a), end(a)
struct SegTree{
int n;
vector<ll> data, lazy;
SegTree(int n): n(n), data(n * 2){}
inline ll get() const {
return data[1];
}
inline void add(int l, int r, int val){
if(l < 0) l = 0;
if(r > n) r = n;
l += n;
r += n;
int L = l, R = r;
for(; L < R; L /= 2, R /= 2){
if(L & 1) data[L++] += val;
if(R & 1) data[--R] += val;
}
r--;
while(l /= 2){
ll a = min(data[l * 2], data[l * 2 | 1]);
if(a){
data[l] += a;
data[l * 2] -= a;
data[l * 2 | 1] -= a;
}
}
while(r /= 2){
ll a = min(data[r * 2], data[r * 2 | 1]);
if(a){
data[r] += a;
data[r * 2] -= a;
data[r * 2 | 1] -= a;
}
}
}
inline void sub(int l, int r, int val){
if(l < 0) l = 0;
if(r > n) r = n;
l += n;
r += n;
int L = l, R = r;
for(; L < R; L /= 2, R /= 2){
if(L & 1) data[L++] += val;
if(R & 1) data[--R] += val;
}
L = l; R = r - 1;
for(int i = __lg(L); i; i--){
const int l = L >> i;
ll a = min(data[l * 2], data[l * 2 | 1]);
if(a){
data[l] += a;
data[l * 2] -= a;
data[l * 2 | 1] -= a;
}
}
for(int i = __lg(R); i; i--){
const int r = R >> i;
ll a = min(data[r * 2], data[r * 2 | 1]);
if(a){
data[r] += a;
data[r * 2] -= a;
data[r * 2 | 1] -= a;
}
}
}
};
int main(){
int m, n, b, p;
scanf("%d %d %d %d", &m, &n, &b, &p);
using tuplis = array<int, 4>;
vector<tuplis> in, out;
rep(p){
int x1, y1, x2, y2, c;
scanf("%d %d %d %d %d", &x1, &y1, &x2, &y2, &c);
x1--; y1--;
in.push_back({x1, y1, y2, c});
out.push_back({x2, y1, y2, -c});
}
sort(all(in));
sort(all(out));
in.push_back({INF, 0, 0, 0});
out.push_back({INF, 0, 0, 0});
auto check = [&](int x) -> bool {
x--;
SegTree seg(n - x);
int i1 = 0, i2 = 0, at = 0;
while(at < m - x){
while(in[i1][0] - x <= at){
seg.add(in[i1][1] - x, in[i1][2], in[i1][3]);
i1++;
}
while(out[i2][0] <= at){
seg.sub(out[i2][1] - x, out[i2][2], out[i2][3]);
i2++;
}
if(seg.get() <= b) return 1;
at = min(in[i1][0] - x, out[i2][0]);
}
return 0;
};
int ok = 0, ng = min(n, m) + 1;
while(ng - ok > 1){
ll cen = (ok + ng) / 2;
if(check(cen)) ok = cen;
else ng = cen;
}
cout << ok << endl;
}
Compilation message (stderr)
pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:79:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d", &m, &n, &b, &p);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pyramid_base.cpp:84:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d %d", &x1, &y1, &x2, &y2, &c);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |