luogu#P7982. [JRKSJ R3] 琴琴的树

    ID: 7273 远端评测题 1500ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2021洛谷原创后缀自动机 SAMO2优化后缀数组 SA

[JRKSJ R3] 琴琴的树

Problem Description

Qinqin has a binary tree that satisfies:

  • The tree has infinitely many nodes.
  • Each node has an index and a weight. Initially, the weight of every node is 00.
  • The root node has index 11.
  • If a node has index ii, then its left and right children have indices 2i2i and 2i+12i+1, respectively.

Qinqin will perform a total of mm operations on the tree. Each operation is one of the following:

  1. Add vv to the weight of every node in the subtree rooted at the node with index xx.
  2. Query the sum of weights of all nodes on the path from the node with index xx to the node with index yy in the tree. The answer is taken modulo 2322^{32}.

However, Qinqin will not directly give xx and yy. Instead, she gives a 0101 sequence aa of length nn. Each time she needs to give xx or yy, she provides an interval [lx,rx][l_x,r_x] or [ly,ry][l_y,r_y]. The number is the value of this interval interpreted as a binary number.

Input Format

The first line contains two integers n,mn,m.
The second line contains a string of length nn representing aa. It is guaranteed that the string contains only 0 and 1.
The next mm lines each contain an operation type, followed by the operation parameters. The formats are:

  1.  lx rx v\ l_x\ r_x\ v
  2.  lx rx ly ry\ l_x\ r_x\ l_y\ r_y

Output Format

For each operation of type 22, output one integer per line representing the answer.

5 5
01010
1 4 5 5
2 1 3 2 5
1 2 3 3
2 1 5 1 2
2 3 4 4 5
15
24
8

Hint

Sample Explanation

The first four levels of the tree are shown in the figure:

Operation 1: Add 55 to the weights of all nodes in the subtree rooted at 22.
Operation 2: Query the sum of weights on the path 2102\rightarrow 10.
Operation 3: Add 33 to the weights of all nodes in the subtree rooted at 22.
Operation 4: Query the sum of weights on the path 10110\rightarrow 1.
Operation 5: Query the sum of weights on the path 121\rightarrow 2.

Constraints

This problem uses bundled testdata.

Subtask\text{Subtask} nn\le mm\le Score
11 1010 10310^3 55
22 2020 10510^5
33 10410^4 2020
44 4×1054\times 10^5 7070

For 100%100\% of the data, 1n,m4×1051\le n,m\le 4\times 10^5, 1v1091\le v \le 10^9, 1lxrxn1\le l_x\le r_x\le n, 1lyryn1\le l_y\le r_y\le n, and it is guaranteed that x,y0x,y\ne 0.

Translated by ChatGPT 5