Grow Gravity

Time limit: 0.3s Memory limit: 64MB Input: Output:

Task

Little Newton likes gravity and plays with a magical shape made out of 1×11 \times 1 squares, suspended in the air.

Initially, this shape is made of only one such square. On this magical shape two things happen (in this order):

  1. Grow phase: Around each square in this shape some new squares will appear. The grow phase can be of two types:
    • Type + The new squares will appear around the squares in only 4 directions (north, south, east and west).
    • Type * The new squares will appear in 8 directions (north, south, east, west, north-east, north-west, south-east and south-west).
  2. Gravity phase: In this phase, Little Newton places a plate under the shape and lets all the squares fall onto it. Note: The plate is removed immediately after this operation!

As an example, the effects of each of the 2 types of grow phases, followed by a gravity phase, are pictured below.

Little Newton has an array v1,,vNv_1, \ldots, v_N of NN types of grow phases and wants to do QQ operations of the following types:

  • update(i)\text{update}(i): If vi=+v_i = + then set it to *; otherwise if vi=v_i = * set it to ++.
  • query(,r)\text{query}(\ell, r): Suppose Little Newton starts with a shape made out of only one 1×11 \times 1 square and applies, for i=,,ri = \ell, \ldots, r, in order, a grow phase of type viv_i followed by a gravity phase. How many 1×11 \times 1 squares will the shape have in the end?

Help Little Newton answer all of these queries.

Input data

The first line of the input contains the number NN. The second line contains NN symbols from among {+,}\{ +, *\}, not separated by spaces, representing the initial values of v1,,vNv_1, \ldots, v_N. The third line of the input contains the number QQ. Then, each of the following QQ lines will contain one of the following: either two integers 1i1\, i representing an update(i)\text{update}(i) operation, or three integers 2r2\,\ell\,r representing a query(,r)\text{query}(\ell, r) operation.

Output data

You should output the answer for each query(,r)\text{query}(\ell, r) operation, each on a new line.

Constraints and clarifications

  • 1N200 0001 \leq N \leq 200 \ 000.
  • 1Q200 0001 \leq Q \leq 200 \ 000.
  • vi{+,}v_i \in \{ +, * \} for 1iN1 \leq i \leq N.
  • t{1,2}t \in \{ 1, 2\}, 1iN1 \leq i \leq N and 1rN1 \leq \ell \leq r \leq N for each operation.
# Points Constraints
1 5 vi=v_i = * for each 1iN1 \leq i \leq N and the operations are only of type 2.
2 10 1N401 \leq N \leq 40 and 1Q401 \leq Q \leq 40.
3 20 1N3001 \leq N \leq 300 and 1Q3001 \leq Q \leq 300.
4 30 vi=+v_i = + for each 1iN1 \leq i \leq N and the operations are only of type 2.
5 35 No further restrictions.

Example

stdin

4
+*++
9
2 2 4
1 3
1 4
2 2 4
1 1
1 2
1 3
1 4
2 2 4

stdout

39
49
31

Explanation

First query. In this query, the sequence of operations is *++. The shape thus has the following configurations.

Hence the answer is 3939.

Second query. In the second query, the sequence of operations is ***. The shape thus has the following configurations.

Therefore, the answer is 4949.

Third query. In the last query, the sequence of operations is +++. The shape thus has the following configurations.

Thus, the answer is 3131.

Log in or sign up to be able to send submissions!