#P4145. 上帝造题的七分钟 2 / 花神游历各国

    ID: 3067 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>线段树并查集枚举,暴力块状链表,块状数组,分块

上帝造题的七分钟 2 / 花神游历各国

Description

"The first minute, X said, let there be a sequence, so a sequence of positive integers was given.

The second minute, L said, it should be modifiable, so there was an operation that takes the floor of the square root of every number in a segment.

The third minute, k said, it should be queryable, so there was an operation to find the sum of a segment.

The fourth minute, Caihong Miao said, make it NOIP difficulty, so there were constraints.

The fifth minute, the poet said, let there be rhythm, so there were time and memory limits.

The sixth minute, He Xue said, save some trouble, so it was guaranteed that during computation and in the final result, all values fit within the representable range of a 6464-bit signed integer type.

The seventh minute, this problem was finally created, but the problem setters no longer wanted to write the program for it."

— "Seven Minutes to Make a Problem · Part II"

So this sacred task is handed to you.

Input Format

The first line contains an integer nn, the number of elements in the sequence.

The second line contains nn positive integers, the initial sequence.

The third line contains an integer mm, the number of operations.

Each of the next mm lines contains three integers k l r.

  • k=0k=0 means replace every number in [l,r][l,r] with the floor of its square root.
  • k=1k=1 means query the sum of the numbers in [l,r][l,r].

It is possible in the testdata that l>rl>r, so when this happens please swap ll and rr.

Output Format

For each query operation, output one answer per line.

10
1 2 3 4 5 6 7 8 9 10
5
0 1 10
1 1 10
1 1 5
0 5 8
1 4 8
19
7
6

Hint

Constraints:

  • For 30% of the testdata, 1n,m1031\le n,m\le 10^3, and the numbers in the sequence do not exceed 3276732767.
  • For 100% of the testdata, 1n,m1051\le n,m\le 10^5, 1l,rn1\le l,r\le n, the numbers in the sequence are greater than 00 and do not exceed 101210^{12}.

Translated by ChatGPT 5