#P14521. 【MX-S11-T2】加减乘除

    ID: 16224 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>贪心线段树树状数组离散化O2优化前缀和差分离线处理梦熊比赛

【MX-S11-T2】加减乘除

Background

Imagine a Future Rose - 20 Levent / Xingchen.

Problem Description

You are given a tree with nn nodes, numbered from 11 to nn. The root is node 11. Each node has an operator (either plus or minus) opi\mathrm{op}_i and a number aia_i. Each edge has an interval [l,r][l, r].

You start at node 11 with a number xx in your hand, and you need to perform the following process:

  • Suppose you are at node uu. You change the number in your hand from xx to xopuaux \mathbin{\mathrm{op}_u} a_u.
  • You may choose to end the process at node uu, or you may choose a child node vv. Suppose the interval on the edge connecting uu and vv is [l,r][l, r]. You must satisfy lxrl \le x \le r, then move to vv and repeat these two steps.

You are given qq queries. In each query, you are given the initial value of xx in your hand. You need to answer how many nodes you can end the process at.

Input Format

The first line contains two integers n,qn, q.

The next n1n - 1 lines: in the ii-th line there are three integers pi+1,li+1,ri+1p_{i+1}, l_{i+1}, r_{i+1}, meaning the parent of node i+1i + 1 is pi+1p_{i+1}, and the interval on the edge connecting them is [li+1,ri+1][l_{i + 1}, r_{i + 1}].

The next nn lines: in the ii-th line there is a character opi\mathrm{op}_i and an integer aia_i.

The next qq lines: each line contains an integer xx.

Output Format

Output qq lines, each line contains one integer, representing the answer.

5 5
1 4 7
1 5 8
2 3 4
2 1 6
+ 3
- 2
+ 1
- 4
+ 7
1
2
3
4
5
3
5
5
4
2

Hint

Sample Explanation #1

When x=1x = 1, you can end the process at nodes 1,2,51, 2, 5.

When x=2x = 2, you can end the process at nodes 1,2,3,4,51, 2, 3, 4, 5.

When x=3x = 3, you can end the process at nodes 1,2,3,4,51, 2, 3, 4, 5.

When x=4x = 4, you can end the process at nodes 1,2,3,51, 2, 3, 5.

When x=5x = 5, you can end the process at nodes 1,31, 3.

Sample #2

See calc/calc2.in\textbf{\textit{calc/calc2.in}} and calc/calc2.ans\textbf{\textit{calc/calc2.ans}} in the contestant directory.

This sample satisfies the constraints of test points 131 \sim 3.

Sample #3

See calc/calc3.in\textbf{\textit{calc/calc3.in}} and calc/calc3.ans\textbf{\textit{calc/calc3.ans}} in the contestant directory.

This sample satisfies the constraints of test points 464 \sim 6.

Sample #4

See calc/calc4.in\textbf{\textit{calc/calc4.in}} and calc/calc4.ans\textbf{\textit{calc/calc4.ans}} in the contestant directory.

This sample satisfies the constraints of test points 797 \sim 9.

Sample #5

See calc/calc5.in\textbf{\textit{calc/calc5.in}} and calc/calc5.ans\textbf{\textit{calc/calc5.ans}} in the contestant directory.

This sample satisfies the constraints of test point 1010.

Sample #6

See calc/calc6.in\textbf{\textit{calc/calc6.in}} and calc/calc6.ans\textbf{\textit{calc/calc6.ans}} in the contestant directory.

This sample satisfies the constraints of test points 112011 \sim 20.

Constraints

There are 2020 test points in this problem, each worth 55 points.

For all testdata, it is guaranteed that:

  • 1n5×1051 \le n \le 5 \times 10^5.
  • 1q1061 \le q \le 10^6.
  • 1018liri1018-10^{18} \le l_i \le r_i \le 10^{18}.
  • 1018x,ai1018-10^{18} \le x, a_i \le 10^{18}.
  • opi{+,}\mathrm{op}_i \in \{ +, - \}.
  • 1pi<i1 \le p_i < i.

::cute-table{tuack}

Test Point ID nn \le qq \le Special Property
131 \sim 3 10310^3 None
464 \sim 6 5×1055 \times 10^5 10610^6 A
797 \sim 9 ^ B
1010 C
112011 \sim 20 None
  • Special Property A: For all 2in2 \le i \le n, pi=i1p_i = i - 1.
  • Special Property B: For all 2in2 \le i \le n, li=103l_i = -10^3 and ri=103r_i = 10^3. Also, for all 1in1 \le i \le n, 103ai103-10^3 \le a_i \le 10^3, and 103x103-10^3 \le x \le 10^3.
  • Special Property C: For all 1in1 \le i \le n, ai=0a_i = 0.

Translated by ChatGPT 5