QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#789190 | #7448. rfplca | Mr_Az | RE | 0ms | 0kb | C++14 | 2.3kb | 2024-11-27 19:29:37 | 2024-11-27 19:29:37 |
answer
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void read(T &x){
x=0;int f=1;char c=getchar();
while(!isdigit(c)){if(c=='-') f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
x*=f;
}
template<typename T,typename ... Args>
void read(T &x, Args &... y){read(x);read(y...);}
const int N = 4e5 + 15;
int n, q, B, a[N], pre[N];
int m, l[N], r[N], flag[N], cnt[N];
#define del(x,d) (max(x - d, 1))
#define pos(i) (i/B+1)
inline void init() {
for (int i = 1; i * B <= n; i++) l[i] = r[i - 1] + 1, r[i] = i * B;
m=n/B;
if (n%B) ++m, l[m] = r[m - 1] + 1, r[m] = n;
}
inline void build(int u) { for (int i = l[u]; i <= r[u]; i++) pre[i] = (a[i] < l[u]) ? a[i] : pre[a[i]]; }
inline void pushdown(int u) {
if (flag[u])
for (int i = l[u]; i <= r[u]; i++) a[i] = del(a[i], flag[u]);
flag[u] = 0; build(u);
}
inline void change(int x, int y, int d) {
if (pos(x) == pos(y)) {
for (int i = x; i <= y; i++) a[i] = del(a[i], d);
build(pos(x));
return;
}
for (int i = x; i <= r[pos(x)]; i++) a[i] = del(a[i], d);
for (int i = l[pos(y)]; i <= y; i++) a[i] = del(a[i], d);
build(pos(x)), build(pos(y));
for (int u = pos(x) + 1; u <= pos(y) - 1; u++) {
flag[u] = min(flag[u] + d, n), cnt[u] = min(cnt[u] + d, n);
if (cnt[u] <= B) pushdown(u); //更新次数较少,暴力重构
}
}
inline int lca(int x, int y) {
while (pos(x) != pos(y)) {
if (pos(x) < pos(y)) swap(x, y);
if (cnt[pos(x)] <= B) x = del(pre[x], flag[pos(x)]);
else x = del(a[x], flag[pos(x)]);
}
while (x != y) {
if (x < y) swap(x, y);
x = del(a[x], flag[pos(x)]);
}
return x;
}
int main() {
read(n), read(q), B = 500;
init();
for (int i = 2; i <= n; i++) read(a[i]);
for (int i = 1; i <= m; i++) build(i);
int lst = 0;
while (q--) {
int opt; read(opt);
if (opt == 1) {
int l, r, x; read(l), read(r), read(x);
l ^= lst, r ^= lst, x ^= lst;
change(l, r, x);
} else {
int u, v; read(u), read(v);
u ^= lst, v ^= lst;
lst = lca(u, v);
printf("%d\n", lst);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
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 1 18 1 4 1 18 1 1 4 1 1 1 1 5 1 4 4 4 11 5 1 4 1 4 1 1 4 1 1 1 4 1 1 1 1 4 4 1 1 1 4 4 1 1 1 1 4 1 1 1 5 1 1 1 1 5 1 1 1 1 4 1 1 12 12 1 1 4 1 1 11 1 1 1 1 4 1 1 1 4 1 1 1 14 1 18 7 5 25 1 62 1 1 1 1 1 1 1 4 4 4 102 1 1 1 1 1 2 1 1 1 1 1 1 1 1 18 4 1 1 4 5 1 1 1 1 1 1 1 1 1 1...