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>
#include <cassert>
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 3e5 + 5;
int n, x[NMAX], xx[NMAX], y[NMAX], chk[NMAX], b, base = 1, k, a, c;
ll ps[NMAX], ans;
vector<pair<int, int>> seg;
vector<pair<int, int>> v;
void update(int idx, int val) {
idx += base;
seg[idx] = { val, idx - base }; idx /= 2;
while (idx) {
seg[idx] = seg[idx * 2];
if (seg[idx * 2 + 1].first < seg[idx].first) seg[idx] = seg[idx * 2 + 1];
idx /= 2;
}
return;
}
int find(int l, int r) {
l += base; r += base;
int h = 2e9, ret;
while (l <= r) {
if (l & 1) {
if (seg[l].first < h) h = seg[l].first, ret = seg[l].second;
l++;
}
else if (!(r & 1)) {
if (seg[r].first < h) h = seg[r].first, ret = seg[r].second;
r--;
}
l /= 2; r /= 2;
}
return ret;
}
double go(int l, int r, int h) {
if (l > r) return 0;
double t = 0;
int lx = x[l], rx = xx[r], ix;
int p = chk[r] - ((l) ? chk[l - 1] : 0);
if (!p) {
ans += ps[r] - ((l) ? ps[l - 1] : 0) - 1LL * h * (rx - lx);
return 0;
}
ix = find(l, r);
double ret = 1.0 * (y[ix] - h) * (rx - lx) / p;
t = max(go(l, ix - 1, y[ix]), go(ix + 1, r, y[ix]));
return ret + t;
}
int main(void) {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed; cout.precision(2);
cin >> n >> b >> b; n = (n - 2) / 2;
while (base < n) base *= 2;
seg.resize(base * 2);
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> xx[i] >> y[i];
update(i, y[i]);
ps[i] = (xx[i] - x[i]) * y[i];
if (i) ps[i] += ps[i - 1];
}
cin >> b >> b;
cin >> k;
for (int i = 0; i < k; i++) {
cin >> a >> c >> b >> c;
v.emplace_back(a, b);
}
sort(all(v));
int ix = 0;
for (int i = 0; i < n; i++) {
if (ix < k && v[ix] == make_pair(x[i], xx[i])) {
chk[i] = 1; ix++;
}
if (i) chk[i] += chk[i - 1];
}
cout << go(0, n - 1, 0) << '\n';
cout << ans;
return 0;
}
Compilation message (stderr)
aqua2.cpp: In function 'int find(int, int)':
aqua2.cpp:39:9: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
39 | return ret;
| ^~~
# | 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... |