#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];
}
assert(ix == k);
cout << go(0, n - 1, 0) << '\n';
cout << ans;
return 0;
}
Compilation message
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;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
292 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Runtime error |
106 ms |
131076 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Runtime error |
113 ms |
131076 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
6448 KB |
Output is correct |
2 |
Correct |
94 ms |
6132 KB |
Output is correct |
3 |
Runtime error |
204 ms |
131076 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |