diff --git a/LibreOJ/144/144.cpp b/LibreOJ/144/144.cpp new file mode 100644 index 00000000..c03f6cfa --- /dev/null +++ b/LibreOJ/144/144.cpp @@ -0,0 +1,88 @@ +#include +#include + +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 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; +} diff --git a/LibreOJ/144/data/144_1.in b/LibreOJ/144/data/144_1.in new file mode 100644 index 00000000..7fe31054 --- /dev/null +++ b/LibreOJ/144/data/144_1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:570993e9ca630c37fe2e075addd1760ffd90676a8ebaf6192be2fa1182606633 +size 147 diff --git a/LibreOJ/144/data/144_1.out b/LibreOJ/144/data/144_1.out new file mode 100644 index 00000000..893c9726 --- /dev/null +++ b/LibreOJ/144/data/144_1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a47ca0ec24965149ec6031cdf2cad3b4b4b5354461420aa853b55f8e9c7a989a +size 20 diff --git a/LibreOJ/144/data/144_2.in b/LibreOJ/144/data/144_2.in new file mode 100644 index 00000000..1d76c1d8 --- /dev/null +++ b/LibreOJ/144/data/144_2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d306069da3587c06918f4cc07327b4386b9d3cbf42152e2420c14f81f370d704 +size 3868639 diff --git a/LibreOJ/144/data/144_2.out b/LibreOJ/144/data/144_2.out new file mode 100644 index 00000000..0936071d --- /dev/null +++ b/LibreOJ/144/data/144_2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f86282b3f6e27d9a4942ce898362facad3722a018d2c0fd0be6932174cc4c851 +size 555957 diff --git a/LibreOJ/144/data/144_3.in b/LibreOJ/144/data/144_3.in new file mode 100644 index 00000000..052fbd0a --- /dev/null +++ b/LibreOJ/144/data/144_3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b3f1e100babc5f9df29fd85ad61da393dd3260f02bed00af47c87171dfd0b44b +size 19536437 diff --git a/LibreOJ/144/data/144_3.out b/LibreOJ/144/data/144_3.out new file mode 100644 index 00000000..0980a75d --- /dev/null +++ b/LibreOJ/144/data/144_3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e8866bc8b32b8e2ecfbb35058debb5c711c291ab3ef9d6556d32fee94ce9fbd8 +size 2428910 diff --git a/LibreOJ/144/data/144_4.in b/LibreOJ/144/data/144_4.in new file mode 100644 index 00000000..fa20d71f --- /dev/null +++ b/LibreOJ/144/data/144_4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:03fe202c639c3f9f2057a1de7aefe99666b1800f2bd7a8a66358115e712b3a3f +size 33954094 diff --git a/LibreOJ/144/data/144_4.out b/LibreOJ/144/data/144_4.out new file mode 100644 index 00000000..073c7632 --- /dev/null +++ b/LibreOJ/144/data/144_4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:109831322ce7e62ca14379967af2682976b1af57f9dde9415d9d70351da84108 +size 3262347 diff --git a/LibreOJ/144/data/144_5.in b/LibreOJ/144/data/144_5.in new file mode 100644 index 00000000..3ddf2593 --- /dev/null +++ b/LibreOJ/144/data/144_5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8098eb9e668a196fbcd275aa8dcab3e5a72453482616f894c5b8f362ad756043 +size 33929419 diff --git a/LibreOJ/144/data/144_5.out b/LibreOJ/144/data/144_5.out new file mode 100644 index 00000000..f9df4897 --- /dev/null +++ b/LibreOJ/144/data/144_5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a835071f23707e41b2d8bc7f334abb2368c8982a2a7d2e0188ad995ecb63756 +size 3419797