Submission #439403

# Submission time Handle Problem Language Result Execution time Memory
439403 2021-06-29T18:19:12 Z 4fecta 수족관 3 (KOI13_aqua3) C++17
84 / 100
1000 ms 109476 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);
}

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;
}

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] = {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--) {
        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 7 ms 9804 KB Output is correct
2 Correct 8 ms 9804 KB Output is correct
3 Correct 7 ms 9932 KB Output is correct
4 Correct 7 ms 9932 KB Output is correct
5 Correct 6 ms 9932 KB Output is correct
6 Correct 7 ms 10060 KB Output is correct
7 Correct 7 ms 10060 KB Output is correct
8 Correct 8 ms 9932 KB Output is correct
9 Correct 6 ms 9932 KB Output is correct
10 Correct 7 ms 9932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 10804 KB Output is correct
2 Correct 11 ms 10700 KB Output is correct
3 Correct 19 ms 11136 KB Output is correct
4 Correct 18 ms 11196 KB Output is correct
5 Correct 23 ms 11084 KB Output is correct
6 Correct 10 ms 11212 KB Output is correct
7 Correct 14 ms 11340 KB Output is correct
8 Correct 18 ms 11212 KB Output is correct
9 Correct 17 ms 11180 KB Output is correct
10 Correct 19 ms 11084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 201 ms 74400 KB Output is correct
2 Correct 213 ms 74384 KB Output is correct
3 Correct 298 ms 96216 KB Output is correct
4 Correct 280 ms 102208 KB Output is correct
5 Correct 287 ms 101956 KB Output is correct
6 Correct 325 ms 109380 KB Output is correct
7 Correct 267 ms 103596 KB Output is correct
8 Correct 279 ms 103556 KB Output is correct
9 Correct 262 ms 100772 KB Output is correct
10 Correct 260 ms 101072 KB Output is correct
11 Correct 276 ms 109476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 243 ms 74388 KB Output is correct
2 Correct 264 ms 74428 KB Output is correct
3 Correct 429 ms 96220 KB Output is correct
4 Correct 447 ms 102084 KB Output is correct
5 Correct 432 ms 101956 KB Output is correct
6 Correct 451 ms 109464 KB Output is correct
7 Correct 350 ms 103620 KB Output is correct
8 Correct 396 ms 103576 KB Output is correct
9 Correct 471 ms 100864 KB Output is correct
10 Correct 502 ms 100804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 74320 KB Time limit exceeded
2 Halted 0 ms 0 KB -