Under construction

Still being built. Things may change

Sequence and Queries 28

Time limit1sMemory limit512 MB

Summary
Maintain an array under range add, range floor-sqrt, and range sum queries, and report each range sum.
Level

Hard8 of 10

Topics
Segment tree, Math, Linked list, Implementation
Solved
No attempts yet

Problem

You are given a sequence A1,A2,…,ANA_1, A_2, \ldots, A_N of length NN. Write a program that performs the following queries.

  • 1 L R X: for every L≤i≤RL \le i \le R, apply Ai=Ai+XA_i = A_i + X.
  • 2 L R: for every L≤i≤RL \le i \le R, apply Ai=⌊Ai⌋A_i = \lfloor \sqrt{A_i} \rfloor.
  • 3 L R: print AL+AL+1+⋯+ARA_L + A_{L+1} + \cdots + A_R.

Input

The first line gives the size of the sequence, NN. (1≤N≤100,0001 \le N \le 100{,}000)

The second line gives A1,A2,…,ANA_1, A_2, \ldots, A_N. (1≤Ai≤100,0001 \le A_i \le 100{,}000)

The third line gives the number of queries, MM. (1≤M≤100,0001 \le M \le 100{,}000)

Each of the next MM lines contains one query. (1≤L≤R≤N1 \le L \le R \le N, 1≤X≤100,0001 \le X \le 100{,}000) At least one query of type 3 is given.

Output

For each query of type 3, print its result on its own line.

Examples1

  1. Example 1

    Input
    5
    1 2 3 4 5
    5
    1 3 5 2
    2 1 4
    3 2 4
    2 3 5
    3 1 5
    
    Expected output
    5
    6