QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#521231#1140. Distributing Candiesarbuzick0 458ms34836kbC++205.8kb2024-08-16 00:51:342024-08-16 00:51:34

Judging History

你现在查看的是最新测评结果

  • [2024-08-16 00:51:34]
  • 评测
  • 测评结果:0
  • 用时:458ms
  • 内存:34836kb
  • [2024-08-16 00:51:34]
  • 提交

answer

#include "candies.h"

#include <bits/stdc++.h>

using namespace std;

constexpr long long inf = (long long)1e18 + 7;

struct Node {
    long long min, second_min, max, second_max;

    bool push_min, push_max;

    long long push_add;

    Node() {
        min = max = 0;
        second_min = inf;
        second_max = -inf;
        push_min = push_max = false;
        push_add = 0;
    }
};

constexpr int R = 1 << 18;

Node tree[R * 2];

void push(int node) {
    if (node >= R) {
        tree[node].push_min = tree[node].push_max = false;
        tree[node].push_add = 0;
        return;
    }
    if (tree[node].push_add != 0) {
        tree[node * 2].min += tree[node].push_add;
        if (tree[node * 2].second_min != inf) {
            tree[node * 2].second_min += tree[node].push_add;
        }
        tree[node * 2].max += tree[node].push_add;
        if (tree[node * 2].second_max != -inf) {
            tree[node * 2].second_max += tree[node].push_add;
        }
        tree[node * 2].push_add += tree[node].push_add;

        tree[node * 2 + 1].min += tree[node].push_add;
        if (tree[node * 2 + 1].second_min != inf) {
            tree[node * 2 + 1].second_min += tree[node].push_add;
        }
        tree[node * 2 + 1].max += tree[node].push_add;
        if (tree[node * 2 + 1].second_max != -inf) {
            tree[node * 2 + 1].second_max += tree[node].push_add;
        }
        tree[node * 2 + 1].push_add += tree[node].push_add;
    }
    tree[node].push_add = 0;
    if (tree[node].push_min) {
        if (tree[node].max < tree[node * 2].max) {
            tree[node * 2].max = tree[node].max;
            tree[node * 2].push_min = true;
        }
        if (tree[node].max < tree[node * 2 + 1].max) {
            tree[node * 2 + 1].max = tree[node].max;
            tree[node * 2 + 1].push_min = true;
        }
    }
    tree[node].push_min = false;
    if (tree[node].push_max) {
        if (tree[node].min > tree[node * 2].min) {
            tree[node * 2].min = tree[node].min;
            tree[node * 2].push_max = true;
        }
        if (tree[node].min > tree[node * 2 + 1].min) {
            tree[node * 2 + 1].min = tree[node].min;
            tree[node * 2 + 1].push_max = true;
        }
    }
    tree[node].push_max = false;
}

void relax(int node) {
    tree[node].min = min(tree[node * 2].min, tree[node * 2 + 1].min);
    if (tree[node].min != tree[node * 2].min) {
        tree[node].second_min = min(tree[node * 2].min, tree[node * 2 + 1].second_min);
    } else if (tree[node].min != tree[node * 2 + 1].min) {
        tree[node].second_min = min(tree[node * 2].second_min, tree[node * 2 + 1].min);
    } else {
        tree[node].second_min = min(tree[node * 2].second_min, tree[node * 2 + 1].second_min);
    }

    tree[node].max = max(tree[node * 2].max, tree[node * 2 + 1].max);
    if (tree[node].max != tree[node * 2].max) {
        tree[node].second_max = max(tree[node * 2].max, tree[node * 2 + 1].second_max);
    } else if (tree[node].max != tree[node * 2 + 1].max) {
        tree[node].second_max = max(tree[node * 2].second_max, tree[node * 2 + 1].max);
    } else {
        tree[node].second_max = max(tree[node * 2].second_max, tree[node * 2 + 1].second_max);
    }
}

void add_val(int ql, int qr, int val, int node = 1, int nl = 0, int nr = R) {
    if (ql <= nl && nr <= qr) {
        tree[node].min += val;
        if (tree[node].second_min != inf) {
            tree[node].second_min += val;
        }
        tree[node].max += val;
        if (tree[node].second_max != -inf) {
            tree[node].second_max += val;
        }
        tree[node].push_add += val;
        return;
    }
    if (qr <= nl || nr <= ql) {
        return;
    }
    push(node);
    int nm = (nl + nr) / 2;
    add_val(ql, qr, val, node * 2, nl, nm);
    add_val(ql, qr, val, node * 2 + 1, nm, nr);
    relax(node);
}

void fix_mn(long long mn, int node = 1, int nl = 0, int nr = R) {
    push(node);
    if (mn <= tree[node].min) {
        return;
    }
    if (mn < tree[node].second_min) {
        tree[node].min = mn;
        tree[node].max = max(tree[node].max, mn);
        if (tree[node].second_max != -inf) {
            tree[node].second_max = max(tree[node].second_max, mn);
        }
        tree[node].push_max = true;
        return;
    }
    int nm = (nl + nr) / 2;
    fix_mn(mn, node * 2, nl, nm);
    fix_mn(mn, node * 2 + 1, nm, nr);
    relax(node);
}

void fix_mx(long long mx, int node = 1, int nl = 0, int nr = R) {
    push(node);
    if (tree[node].max <= mx) {
        return;
    }
    if (mx > tree[node].second_max) {
        tree[node].max = mx;
        tree[node].min = min(tree[node].min, mx);
        if (tree[node].second_min != inf) {
            tree[node].second_min = min(tree[node].second_min, mx);
        }
        tree[node].push_min = true;
        return;
    }
    push(node);
    int nm = (nl + nr) / 2;
    fix_mx(mx, node * 2, nl, nm);
    fix_mx(mx, node * 2 + 1, nm, nr);
    relax(node);
}

long long get(int pos, int node = 1, int nl = 0, int nr = R) {
    if (nl == pos && nr == pos + 1) {
        return tree[node].min;
    }
    if (nr <= pos || pos < nl) {
        return 0;
    }
    push(node);
    int nm = (nl + nr) / 2;
    long long ans = get(pos, node * 2, nl, nm) + get(pos, node * 2 + 1, nm, nr);
    relax(node);
    return ans;
}

vector<int> distribute_candies(vector<int> c, vector<int> l,
                               vector<int> r, vector<int> v) {
    int n = c.size();
    int q = v.size();
    vector<int> ans(n);
    for (int i = 0; i < q; ++i) {
        r[i]++;
        add_val(l[i], r[i], v[i]);
        fix_mn(0);
        fix_mx(c[0]);
    }
    for (int i = 0; i < n; ++i) {
        ans[i] = get(i);
    }
    return ans;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 28436kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
8
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
8
0 7 1
0 7 1
0 7 300000000
0 7 994967293
0 7 1
0 7 1000000000
0 7 1000000000
0 7 1000000000

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
0 0 0 0 0 0 0 0

result:

wrong answer 3rd lines differ - expected: '1000000000 1000000000 10000000...000000000 1000000000 1000000000', found: '0 0 0 0 0 0 0 0'

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 458ms
memory: 34836kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
200000
11408901 370732653 37843 28 53693 15782410 103 297546 1112427 170319071 26 1 6172 11614171 431 884673599 1 3 50085 154 57 28200 145886 898969 74758 72 845768 6 69787 11 31012465 55362 253 2363145 47186217 1103 19622 594 7867 1 4299 28130 48 4689582 12 ...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
87153 87153 243257 250497 325876 406667 525479 655951 766665 971468 1073487 1084603 1144515 1257294 1514842 1536484 1739854 1833903 1950484 1950484 2050477 2096517 2213442 2241808 2453123 2551636 2688712 2735237 2969818 2969818 3043755 3043755 3113712 3297...

result:

wrong answer 3rd lines differ - expected: '87153 87153 37843 28 53693 406...46468 9 1756 429030 247071 1629', found: '87153 87153 243257 250497 3258...1546 474919 429030 247071 16020'

Subtask #3:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 0ms
memory: 28416kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
1000
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

wrong answer 3rd lines differ - expected: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 3ms
memory: 28688kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
10
11 440 51 41 11 1 3 108 148 14
10
0 9 60
0 9 -9
0 9 -30
0 9 41
0 9 82
0 9 69
0 9 -79
0 9 -39
0 9 72
0 9 41

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
208 208 208 208 208 208 208 208 208 208

result:

wrong answer 3rd lines differ - expected: '11 208 51 41 11 1 3 108 143 14', found: '208 208 208 208 208 208 208 208 208 208'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%