# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
439398 |
2021-06-29T18:07:22 Z |
4fecta |
수족관 3 (KOI13_aqua3) |
C++17 |
|
1000 ms |
58964 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], st[MN][LOG], 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];
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 mn = 0x3f3f3f3f, id = 0;
for (int i = l; i <= r; i++) if (hgt[i] < mn) mn = hgt[i], id = i;
return id;
}
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;
}
int mx = -1, node = 0;
void dfs(int cur, int sum) {
sum += val[cur];
if (sum > mx) mx = sum, node = cur;
for (int nxt : a[cur]) dfs(nxt, sum);
}
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] = 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] = hgt[st[i][j - 1]] < hgt[st[i + (1 << (j - 1))][j - 1]] ? 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--) {
mx = -1, node = 0;
dfs(1, 0);
ans += mx;
int cur = node;
while (cur) val[cur] = 0, cur = par[cur];
}
printf("%lld\n", ans);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
9804 KB |
Output is correct |
2 |
Correct |
7 ms |
9832 KB |
Output is correct |
3 |
Correct |
9 ms |
9932 KB |
Output is correct |
4 |
Correct |
8 ms |
9932 KB |
Output is correct |
5 |
Correct |
8 ms |
9932 KB |
Output is correct |
6 |
Correct |
8 ms |
9932 KB |
Output is correct |
7 |
Correct |
8 ms |
9932 KB |
Output is correct |
8 |
Correct |
8 ms |
9932 KB |
Output is correct |
9 |
Correct |
8 ms |
9932 KB |
Output is correct |
10 |
Correct |
8 ms |
9932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
10476 KB |
Output is correct |
2 |
Correct |
12 ms |
10484 KB |
Output is correct |
3 |
Correct |
23 ms |
10872 KB |
Output is correct |
4 |
Correct |
18 ms |
10872 KB |
Output is correct |
5 |
Correct |
22 ms |
10828 KB |
Output is correct |
6 |
Correct |
17 ms |
10948 KB |
Output is correct |
7 |
Correct |
17 ms |
10828 KB |
Output is correct |
8 |
Correct |
27 ms |
10860 KB |
Output is correct |
9 |
Correct |
21 ms |
10780 KB |
Output is correct |
10 |
Correct |
25 ms |
10828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
250 ms |
53848 KB |
Output is correct |
2 |
Correct |
221 ms |
58868 KB |
Output is correct |
3 |
Execution timed out |
1071 ms |
43296 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
248 ms |
53892 KB |
Output is correct |
2 |
Correct |
267 ms |
58964 KB |
Output is correct |
3 |
Execution timed out |
1085 ms |
43136 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1095 ms |
53780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |