QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#384922#7448. rfplcaalpha1022WA 438ms8504kbC++141.7kb2024-04-10 13:51:192024-04-10 13:51:19

Judging History

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

  • [2024-04-10 13:51:19]
  • 评测
  • 测评结果:WA
  • 用时:438ms
  • 内存:8504kb
  • [2024-04-10 13:51:19]
  • 提交

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 getFa(int u) { return max(a[u] - tag[pos[u]], 0); }
int getAnc(int u) { return mx[pos[u]] <= (pos[u] - 1) * B ? getFa(u) : anc[u]; }
int query(int u, int v) {
  while (1) {
    int fu = getAnc(u), fv = getAnc(v);
    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 = getFa(u);
  }
  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);
  }
}

详细

Test #1:

score: 0
Wrong Answer
time: 438ms
memory: 8504kb

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
5
5
11
6
1
1
4
5
1
1
1
1
1
1
1
4
1
40
5
4
1
110
1
1
1
8
1
1
1
1
1
1
4
1
4
1
4
1
1
1
1
4
86
1
1
7
17
1
4
1
4
1
4
1
1
1
1
7
1
6
4
1
1
1
1
1
1
1
1
5
4
1
1
1
4
1
1
12
5
1
4
1
1
1
1
1
4
4
12
1
1
1
1
4
1
4
4
1
11
1
1
1
1
1
1
1
1
1
4
5
1
4
1
1
5
1
1
1
1
1
1
5
10
4
1
1
1
1
1
4
4
1
1
1
...

result:

wrong answer 12th lines differ - expected: '1', found: '5'