답안 #439392

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439392 2021-06-29T17:56:26 Z 4fecta 수족관 3 (KOI13_aqua3) C++17
18 / 100
207 ms 58944 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, 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, val[MN], par[MN], ans, tim = 1, in[MN * 2], out[MN * 2], rev[MN * 2], lzy[MN * 6];
vector<int> a[MN];
pii seg[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, int 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 hgt[st[l][j]] < hgt[st[r - (1 << j) + 1][j]] ? st[l][j] : st[r - (1 << j) + 1][j];
}

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] = 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--) {
        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 (val[cur]) {
            upd(1, num * 2, in[cur], out[cur], -val[cur], 1);
            val[cur] = 0;
            cur = par[cur];
        }
    }
    printf("%lld\n", ans);

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9804 KB Output is correct
2 Correct 7 ms 9804 KB Output is correct
3 Correct 7 ms 9932 KB Output is correct
4 Correct 6 ms 9872 KB Output is correct
5 Correct 7 ms 9932 KB Output is correct
6 Correct 7 ms 9892 KB Output is correct
7 Correct 7 ms 9932 KB Output is correct
8 Correct 6 ms 9932 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 10444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 207 ms 58944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 187 ms 58852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 186 ms 58880 KB Output isn't correct
2 Halted 0 ms 0 KB -