[BZOJ4154] [IPSC2015] Generating Synergy
Question Description
Given a root tree with a root of 1, the initial all node color is 1, each time a node A is not more than L of A's child nodes dyed C, or asked the color of point a
Input
The first line is a number T, which represents the number of data groups the first row of the next group of data is three n,c,q representing the number of nodes, the number of colors and the number of operands the next line n-1 the number 2: n the parent node next Q row Three number of A,l,c if C is 0, indicating the color of a or not more than L of a sub-node dyed c
Output
Set currently is the first operation, y_i for the answer of this inquiry (if this operation is a modification y_i is 0), so z_i=i*y_i, output z_1+z_2+...+z_q die 10^9+7
Input example
14 3 71 2 23 0 02 1 33 0 01 0 22 0 04 1 14 0 0
Output example
32
Data size and conventions
For 100% of data t<=6,n,m,c<=10^5,1<=a<=n,0<=l<=n,0<=c<=c
Exercises
At first I read the wrong question ... Only then found the point in the subtree.
Then you can use the DFS sequence of each node as the horizontal axis, the depth as the ordinate, then you can put a tree in the coordinate system, a node, the distance for L is the vertical axis from dep[a] to Dep[a] + L, horizontal axis from dfsx[a] to Dfsx[a] + siz[a ]-1 of the rectangle, where Dep[a] represents the depth of Node A, dfsx[a] refers to the DFS order of Node A, Siz[a] represents the subtree size with Node A as the root. You need to mark the next pass.
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <stack > #include <vector> #include <queue> #include <cstring> #include <string> #include <map > #include <set>using namespace std;const int buffersize = 1 << 16;char buffer[buffersize], *head, *TAIL;INL ine Char Getchar () {if (Head = = Tail) {int L = fread (buffer, 1, buffersize, stdin); Tail = (Head = buffer) + L; } return *head++;} int read () {int x = 0, f = 1; char c = Getchar (); while (!isdigit (c)) {if (c = = '-') f =-1; c = Getchar ();} while (IsDigit (c)) {x = x * + C-' 0 '; c = Getchar ();} return x * f;} #define MAXN 100010#define maxm 200010#define oo 2147483647#define MOD 1000000007#define LL long longint N, M, FA[MAXN], D EP[MAXN], HEAD[MAXN], NEXT[MAXM], TO[MAXM], DL[MAXN], dr[maxn];void addedge (int a, int b) {To[++m] = b; next[m] = Head[a]; Head[a] = M;swap (A, b); to[++m] = b; NEXT[M] = Head[a]; head[A] = M;return;} int clo;void build (int u, int d) {Dl[u] = ++clo; Dep[u] = d;for (int e = Head[u]; e = next[e]) if (to[e]! = Fa[u]) build ( To[e], D + 1);d r[u] = Clo;return;} int root, LC[MAXN], Rc[maxn];bool cur;struct Node {int x[2], mx[2], mn[2], col, setv;bool operator < (const node& T ) const {return x[cur] < t.x[cur];} BOOL operator = = (CONST node& t) const {return x[0] = = T.x[0] && x[1] = = T.x[1];}} Ns[maxn];void maintain (int o) {int l = Lc[o], r = rc[o];for (int i = 0; i < 2; i++) {Ns[o].mx[i] = max (max (ns[l].mx[i), Ns[r].mx[i]), ns[o].x[i]); Ns[o].mn[i] = min (min (ns[l].mn[i], ns[r].mn[i]), ns[o].x[i]);} return;} void Build (int& o, int L, int R, bool cur) {if (L > R) {o = 0; return;} int M = L + R >> 1; o = M; Cur = Cur; Nth_element (ns + L, NS + M, NS + R + 1), build (Lc[o], L, M-1, cur ^ 1); Build (Rc[o], M + 1, R, cur ^ 1); maintain (o); return;} Node x, y;void pushdown (int o) {if (!ns[o].setv) return; ns[o].col = Ns[lc[o]].setv = Ns[rc[o]].setv = Ns[o].setv; Ns[o].setv = 0;return;} BOOL All (int o) {return x.x[0] <= ns[o].mn[0] && ns[o].mx[0] <= y.x[0] && x.x[1] <= ns[o].mn[1] && ns[o].mx[1] <= y.x[1]; }bool has (int o) {return! Ns[o].mx[0] < x.x[0] | | Ns[o].mn[0] > y.x[0] | | NS[O].MX[1] < x.x[1] | | NS[O].MN[1] > Y.x[1]); }void Update (int o, int c) {if (!o) return;p Ushdown (o), int xx = ns[o].x[0], yy = Ns[o].x[1];if (x.x[0] <= xx && XX <= y.x[0] && x.x[1] <= yy && yy <= y.x[1]) Ns[o].col = C;if (All (Lc[o])) Ns[lc[o]].setv = C;els E if (have (Lc[o])) update (Lc[o], C), if (All (rc[o)) Ns[rc[o]].setv = C;else if (have (Rc[o])) update (Rc[o], c); return;} int query (int o) {if (!o) Return-1;pushdown (o), if (x = = Ns[o]) return ns[o].col;int tmp = -1;if (ns[lc[o]].mn[0] <= x.x[0 ] && x.x[0] <= ns[lc[o]].mx[0] && ns[lc[o]].mn[1] <= x.x[1] && x.x[1] <= ns[lc[o]].mx[1]) TMP = query (Lc[o]), if (TMP < 0) tmp = query (Rc[o]); return TMP;} InchT Main () {ns[0].mx[0] = ns[0].mx[1] =-oo;ns[0].mn[0] = ns[0].mn[1] = Oo;int T = Read (), while (t--) {m = 0; memset (head, 0, sizeof (head)); n = read (); int c = Read (), q = Read (), for (int i = 2; I <= n; i++) Addedge (fa[i] = read (), i); clo = 0; Build (1, 1); for (int i = 1; I <= n; i++) ns[i].x[0] = Dl[i], ns[i].x[1] = Dep[i], Ns[i].col = 1, Ns[i].setv = 0;build (ro OT, 1, n, 0); LL ans = 0;for (int i = 1; I <= Q; i++) {int a = read (), L = Read (), C = Read (), TMP = 0;if (c) {x.x[0] = Dl[a]; y.x[0] = Dr[a]; X.X[1] = Dep[a]; Y.X[1] = Dep[a] + l;update (root, c);} else {x.x[0] = Dl[a]; x.x[1] = Dep[a];tmp = query (root);} Ans + = (LL) tmp * i;if (ans >= mod) ans%= mod;} printf ("%lld\n", ans);} return 0;}
[BZOJ4154] [IPSC2015] Generating Synergy