QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#384916#7448. rfplcaalpha1022WA 463ms8580kbC++141.6kb2024-04-10 13:47:242024-04-10 13:47:25

Judging History

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

  • [2024-04-10 13:47:25]
  • 评测
  • 测评结果:WA
  • 用时:463ms
  • 内存:8580kb
  • [2024-04-10 13:47:24]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 4e5;
const int B = 632;
const int C = (N - 1) / B + 1;

int n, m;
int a[N + 5], pos[N + 5], anc[N + 5];
int mx[C + 5], tag[C + 5];
void build(int p) {
  int l = (p - 1) * B + 1, r = min(p * B, n - 1);
  mx[p] = 0;
  for (int i = l; i <= r; ++i) mx[p] = max(mx[p], a[i] = max(a[i] - tag[p], 0));
  for (int i = l; i <= r; ++i)
    anc[i] = a[i] < l ? a[i] : anc[a[i]];
}
void update(int l, int r, int k) {
  for (int i = l; i <= min(pos[l] * B, r); ++i) a[i] = max(a[i] - k, 0);
  build(pos[l]);
  if (pos[l] == pos[r]) return ;
  for (int i = (pos[r] - 1) * B + 1; i <= r; ++i) a[i] = max(a[i] - k, 0);
  build(pos[r]);
  for (int p = pos[l] + 1; p < pos[r]; ++p) {
    int l = (p - 1) * B + 1;
    tag[p] += k;
    if (mx[p] < l) mx[p] = max(mx[p] - k, 1);
    else build(p);
  }
}
int query(int u, int v) {
  while (1) {
    int fu = max(anc[u] - tag[pos[u]], 0), fv = max(anc[v] - tag[pos[v]], 0);
    if (fu == fv) break;
    if (fu < fv) swap(u, v), swap(fu, fv);
    u = fu;
  }
  while (u != v) {
    if (u < v) swap(u, v);
    u = max(a[u] - tag[pos[u]], 0);
  }
  return u;
}

int lastans;

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; ++i) scanf("%d", a + i), --a[i], pos[i] = (i - 1) / B + 1;
  for (int p = 1; p <= pos[n - 1]; ++p) build(p);
  for (; m; --m) {
    int op, x, y, z; scanf("%d%d%d", &op, &x, &y), x ^= lastans, y ^= lastans, --x, --y;
    if (op == 1) scanf("%d", &z), z ^= lastans, update(x, y, z);
    else printf("%d\n", lastans = query(x, y) + 1);
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 463ms
memory: 8580kb

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
1
4
1
4
7
21
1
1
5
1
1
1
1
1
1
1
1
11
1
5
4
5
18
4
4
1
1
4
1
32
1
1
1
1
1
1
1
4
1
4
4
1
1
4
1
4
1
1
1
1
32
1
1
1
1
5
1
6
1
1
1
1
1
1
1
18
1
1
4
4
4
97
1
1
1
4
4
1
1
12
1
1
4
1
1
1
12
1
4
1
1
1
14
1
1
1
4
3
1
1
1
1
1
1
1
4
1
1
1
5
1
1
1
1
4
1
1
1
1
1
1
4
1
1
1
4
26
1
1
1
1
16
1
18
1...

result:

wrong answer 13th lines differ - expected: '1', found: '4'