0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 19:25:25 +00:00
https://loj.ac/s/2120655
This commit is contained in:
Baoshuo Ren 2024-07-31 11:32:38 +08:00
parent 25c1839311
commit af29bbe0c9
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
11 changed files with 118 additions and 0 deletions

88
LibreOJ/144/144.cpp Normal file
View File

@ -0,0 +1,88 @@
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e6 + 5;
int n, m, r, v[N];
long long f[N];
int cnt, in[N], out[N];
std::vector<int> g[N];
int lowbit(int x) {
return x & -x;
}
void add(int x, int y) {
for (int i = x; i <= n; i += lowbit(i)) {
f[i] += y;
}
}
long long query(int x) {
long long res = 0;
for (int i = x; i; i -= lowbit(i)) {
res += f[i];
}
return res;
}
void dfs(int u, int f) {
in[u] = ++cnt;
add(cnt, v[u]);
for (int v : g[u]) {
if (v == f) continue;
dfs(v, u);
}
out[u] = cnt;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> r;
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
for (int i = 1, u, v; i < n; i++) {
cin >> u >> v;
g[u].emplace_back(v);
g[v].emplace_back(u);
}
dfs(r, 0);
while (m--) {
int op;
cin >> op;
if (op == 1) {
int a, x;
cin >> a >> x;
add(in[a], x);
} else { // op == 2
int a;
cin >> a;
cout << query(out[a]) - query(in[a] - 1) << endl;
}
}
return 0;
}

BIN
LibreOJ/144/data/144_1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/144/data/144_1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/144/data/144_2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/144/data/144_2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/144/data/144_3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/144/data/144_3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/144/data/144_4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/144/data/144_4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/144/data/144_5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/144/data/144_5.out (Stored with Git LFS) Normal file

Binary file not shown.