QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#387188#7448. rfplcasuomynonATL 0ms0kbC++202.0kb2024-04-12 08:49:522024-04-12 08:49:53

Judging History

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

  • [2024-04-12 08:49:53]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-04-12 08:49:52]
  • 提交

answer

#include <bits/stdc++.h>
const int N = 4e5, S = 6.4e2, T = 6.4e2;
int n, q, fa[N + 5], pre[N + 5], pos[N + 5];
struct Block {
    int l, r, tag, mx;
    void build() {
        mx = 0;
        for (int i = l; i <= r; ++i) {
            fa[i] = std::max(fa[i] - tag, 1), mx = std::max(mx, fa[i]);
            if (fa[i] < l) pre[i] = fa[i];
            else pre[i] = pre[fa[i]];
        }
        tag = 0;
    }
    void update(int v) {
        if (mx < l) { tag -= v; return ; }
        for (int i = l; i <= r; ++i) fa[i] = std::max(fa[i] - v, 1);
        build();
    }
}ar[T + 5];
int query(int x) { return std::max(pre[x] - ar[pos[x]].tag, 0); }
int getfa(int x) { return x == 1 ? 0 : std::max(fa[x] - ar[pos[x]].tag, 1); }
int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
    std::cin >> n >> q;
    for (int i = 2; i <= n; ++i) std::cin >> fa[i];
    for (int i = 1; i <= n; ++i) pos[i] = (i - 1) / S + 1;
    for (int i = 1; i <= pos[n]; ++i) ar[i].l = (i - 1) * S + 1, ar[i].r = std::min(i * S, n);
    for (int i = 1; i <= pos[n]; ++i) ar[i].build();
    for (int op, x, y, v, las = 0; q--;) {
        std::cin >> op >> x >> y, x ^= las, y ^= las;
        if (op == 1) {
            std::cin >> v, v ^= las;
            int p = pos[x], q = pos[y];
            if (p == q) {
                for (int i = x; i <= y; ++i) fa[i] -= v;
                ar[p].build();
                continue;
            }
            for (int i = x; i <= ar[p].r; ++i) fa[i] -= v;
            for (int i = ar[q].l; i <= y; ++i) fa[i] -= v;
            ar[p].build(), ar[q].build();
            for (int i = p + 1; i < q; ++i) ar[i].update(v);
        }else {
            while (query(x) != query(y)) {
                if (query(x) < query(y)) std::swap(x, y);
                x = query(x);
            }
            while (x != y) {
                if (getfa(x) < getfa(y)) std::swap(x, y);
                x = getfa(x);
            }
            std::cout << (las = x) << "\n";
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

400000 400000
1 2 1 4 1 1 5 4 6 5 9 1 1 13 3 8 12 16 3 11 8 8 2 18 21 15 7 23 11 6 4 26 17 5 12 6 5 28 32 26 21 5 19 1 25 25 11 26 47 11 31 25 18 7 25 36 40 23 54 31 14 62 61 33 57 40 11 16 24 51 69 25 55 51 55 65 34 19 18 21 20 62 64 83 22 48 67 47 21 27 30 63 10 14 70 63 18 17 74 98 40 89 10 7 30 ...

output:

1
1
1
1
1
1
4
1
1
18
4
1
1
1
1
4
1
18
1
5
1
8
1
1
1
5
11
1
4
1
1
4
1
4
1
1
1
1
1
1
4
1
4
5
1
1
18
1
1
1
1
1
8
1
5
215
4
1
1
1
5
4
5
4
5
1
1
1
1
1
4
1
4
4
1
1
1
1
4
1
1
4
5
4
5
1
40
1
1
32
4
4
1
16
5
1
4
1
4
2
1
1
1
4
1
5
12
1
1
1
1
1
1
1
4
7
5
4
4
1
1
1
1
4
12
1
4
1
1
1
1
1
5
5
1
1
1
1
1
1
1
745
1
4...

result: