#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<ll, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
#define y1 fqdkqwdpjdqwpow
const int MN = 300005, LOG = 20;
int n, x1, y1, x2, y2, k, len[MN], hgt[MN], psa[MN], lg[MN], num = 1, vis[MN * 2], val[MN * 2], par[MN * 2], tim = 1, in[MN * 4], out[MN * 4], rev[MN * 4];
vector<int> a[MN];
pii seg[MN * 6], st[MN][LOG];
ll ans, lzy[MN * 6];
void build(int l, int r, int idx) {
if (l == r) {seg[idx].s = l; return;}
int mid = (l + r) >> 1;
build(l, mid, idx * 2), build(mid + 1, r, idx * 2 + 1);
}
void push_down(int idx, int l, int r) {
if (!lzy[idx]) return;
seg[idx].f += lzy[idx];
if (l != r) lzy[idx * 2] += lzy[idx], lzy[idx * 2 + 1] += lzy[idx];
lzy[idx] = 0;
}
void upd(int l, int r, int x, int y, ll amt, int idx) {
push_down(idx, l, r);
if (r < x || l > y) return;
if (r <= y && l >= x) {
lzy[idx] += amt;
push_down(idx, l, r);
return;
}
int mid = (l + r) >> 1;
upd(l, mid, x, y, amt, idx * 2), upd(mid + 1, r, x, y, amt, idx * 2 + 1);
seg[idx] = max(seg[idx * 2], seg[idx * 2 + 1]);
}
int qry(int l, int r) {
int j = lg[r - l + 1];
return min(st[l][j], st[r - (1 << j) + 1][j]).s;
}
void build(int cur, int l, int r, int h) {
int i = qry(l, r);
//printf("%d %d %d\n", l, r, i);
val[cur] = (psa[r] - psa[l - 1]) * (hgt[i] - h);
if (l < i) a[cur].push_back(++num), par[num] = cur, build(num, l, i - 1, hgt[i]);
if (i < r) a[cur].push_back(++num), par[num] = cur, build(num, i + 1, r, hgt[i]);
}
void dfs(int cur) {
in[cur] = tim;
rev[tim++] = cur;
for (int nxt : a[cur]) dfs(nxt);
out[cur] = tim;
rev[tim++] = cur;
}
int32_t main() {
boost();
lg[1] = 0;
for (int i = 2; i < MN; i++) lg[i] = lg[i / 2] + 1;
cin >> n;
cin >> x1 >> y1;
n = n / 2 - 1;
for (int i = 1; i <= n; i++) {
cin >> x1 >> y1 >> x2 >> y2;
assert(y1 == y2);
len[i] = x2 - x1;
hgt[i] = y1;
psa[i] = psa[i - 1] + len[i];
st[i][0] = {hgt[i], i};
//printf("%d %d\n", len[i], hgt[i]);
}
for (int j = 1; j < LOG; j++) {
for (int i = 1; i + (1 << j) - 1 <= n; i++) {
st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
}
}
build(1, 1, n, 0);
dfs(1);
build(1, num * 2, 1);
for (int i = 1; i <= num; i++) {
/*printf("node/val %d/%d\n", i, val[i]);
printf("children: ");
for (int p : a[i]) printf("%d ", p);
printf("\n");*/
upd(1, num * 2, in[i], out[i], val[i], 1);
}
cin >> x1 >> y1 >> k;
while (k--) {
push_down(1, 1, num * 2);
pii tmp = seg[1];
ans += tmp.f;
int cur = rev[tmp.s];
//printf("%d %d %d\n", tmp.f, tmp.s, cur);
while (cur && !vis[cur]) {
upd(1, num * 2, in[cur], out[cur], -val[cur], 1);
val[cur] = 0;
vis[cur] = 1;
cur = par[cur];
}
}
printf("%lld\n", ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9804 KB |
Output is correct |
2 |
Correct |
6 ms |
9804 KB |
Output is correct |
3 |
Correct |
7 ms |
9932 KB |
Output is correct |
4 |
Correct |
6 ms |
9932 KB |
Output is correct |
5 |
Correct |
6 ms |
9944 KB |
Output is correct |
6 |
Correct |
7 ms |
10060 KB |
Output is correct |
7 |
Correct |
7 ms |
10040 KB |
Output is correct |
8 |
Correct |
6 ms |
10012 KB |
Output is correct |
9 |
Correct |
7 ms |
9932 KB |
Output is correct |
10 |
Correct |
7 ms |
9932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
10788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
208 ms |
74508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
213 ms |
74316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
202 ms |
74308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |