# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
439405 |
2021-06-29T18:25:30 Z |
4fecta |
수족관 3 (KOI13_aqua3) |
C++17 |
|
400 ms |
104856 KB |
#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);
seg[idx] = max(seg[idx * 2], seg[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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9804 KB |
Output is correct |
2 |
Correct |
6 ms |
9880 KB |
Output is correct |
3 |
Correct |
6 ms |
9932 KB |
Output is correct |
4 |
Correct |
6 ms |
9932 KB |
Output is correct |
5 |
Correct |
6 ms |
10044 KB |
Output is correct |
6 |
Correct |
7 ms |
10060 KB |
Output is correct |
7 |
Correct |
7 ms |
9932 KB |
Output is correct |
8 |
Correct |
6 ms |
10060 KB |
Output is correct |
9 |
Correct |
7 ms |
9932 KB |
Output is correct |
10 |
Correct |
7 ms |
10060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
10828 KB |
Output is correct |
2 |
Correct |
9 ms |
10828 KB |
Output is correct |
3 |
Correct |
10 ms |
11212 KB |
Output is correct |
4 |
Correct |
11 ms |
11212 KB |
Output is correct |
5 |
Correct |
10 ms |
11212 KB |
Output is correct |
6 |
Correct |
10 ms |
11340 KB |
Output is correct |
7 |
Correct |
9 ms |
11148 KB |
Output is correct |
8 |
Correct |
10 ms |
11212 KB |
Output is correct |
9 |
Correct |
10 ms |
11212 KB |
Output is correct |
10 |
Correct |
10 ms |
11212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
198 ms |
74476 KB |
Output is correct |
2 |
Correct |
201 ms |
74528 KB |
Output is correct |
3 |
Correct |
284 ms |
97348 KB |
Output is correct |
4 |
Correct |
286 ms |
97188 KB |
Output is correct |
5 |
Correct |
305 ms |
97348 KB |
Output is correct |
6 |
Correct |
391 ms |
104828 KB |
Output is correct |
7 |
Correct |
315 ms |
98936 KB |
Output is correct |
8 |
Correct |
333 ms |
98688 KB |
Output is correct |
9 |
Correct |
260 ms |
95172 KB |
Output is correct |
10 |
Correct |
251 ms |
95188 KB |
Output is correct |
11 |
Correct |
371 ms |
104824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
208 ms |
75136 KB |
Output is correct |
2 |
Correct |
211 ms |
75064 KB |
Output is correct |
3 |
Correct |
283 ms |
97404 KB |
Output is correct |
4 |
Correct |
282 ms |
97388 KB |
Output is correct |
5 |
Correct |
275 ms |
97332 KB |
Output is correct |
6 |
Correct |
388 ms |
104856 KB |
Output is correct |
7 |
Correct |
339 ms |
98908 KB |
Output is correct |
8 |
Correct |
326 ms |
98912 KB |
Output is correct |
9 |
Correct |
284 ms |
95892 KB |
Output is correct |
10 |
Correct |
246 ms |
95916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
297 ms |
75364 KB |
Output is correct |
2 |
Correct |
354 ms |
80516 KB |
Output is correct |
3 |
Correct |
378 ms |
103260 KB |
Output is correct |
4 |
Correct |
386 ms |
103176 KB |
Output is correct |
5 |
Correct |
400 ms |
103384 KB |
Output is correct |
6 |
Correct |
366 ms |
104624 KB |
Output is correct |
7 |
Correct |
341 ms |
104772 KB |
Output is correct |
8 |
Correct |
381 ms |
101992 KB |
Output is correct |
9 |
Correct |
383 ms |
102116 KB |
Output is correct |