Imelda's Shopping Spree

Maintain a sequence of prices under range-add and range-reverse, and after each update output the number of contiguous segments whose values are strictly increasing.

Hard9Segment treeArrayDynamic programmingImplementationNo attempts yetTime limit5sMemory limit512 MB

Problem

Shoe Wariwap is the most famous shoe boutique in the world. Every day the shop displays NN of the finest pairs of shoes ever made. Each pair stands on its own pedestal, and the pedestals are arranged in a row. The pedestals are numbered from 11 to NN, where pedestal 11 is the leftmost one.

When Shoe Wariwap opens, the pair on pedestal ii is worth pip_i pesos. During the day the manager may raise prices or shuffle the display order so that the less appreciated pairs get more attention. At any moment the manager picks a set of pedestals

Si,j={i,i+1,,j1,j}S_{i,j} = \{i, i+1, \dots, j-1, j\}

and does one of the following.

  • INCREASE the price of the shoes standing on the chosen pedestals. The shoes on pedestals ii through jj each become kk pesos more expensive. The price belongs to the shoes, not to the pedestal.
  • REVERSE the order of the shoes on the chosen pedestals. The pair that was on pedestal ii moves to pedestal jj, the pair that was on pedestal i+1i+1 moves to pedestal j1j-1, and so on.

Today is the birthday of one of Shoe Wariwap's best customers, Imelda. If it were up to her, she would buy all NN pairs. Her husband Marshall tells her they are deep in debt, so the two agree on a system that decides which pairs she buys.

The system works like this. Imelda picks two integers aa and bb with aba \le b. Her chosen shoes are the ones that currently stand on pedestals aa through bb. Marshall adds one more condition, which the couple fondly calls Marshall's Law. Marshall's Law says that Imelda's chosen shoes, read from left to right, must increase in price. That is, if m<nm < n, then the pair on pedestal nn must be more expensive than the pair on pedestal mm. If the chosen shoes break Marshall's Law, the couple goes home with nothing and Marshall vows never to return to Shoe Wariwap.

Imelda is still excited about her big shopping day. Every time the manager changes something, she wants to know how many ways she can fill her shopping bag while obeying Marshall's Law. She would never go home empty handed on her birthday, so she buys at least one pair. For example, consider N=5N = 5 pairs with the following prices.

Shoe AShoe BShoe CShoe DShoe E
69000 pesos1000 pesos1000 pesos2000 pesos3000 pesos
Pedestal 1Pedestal 2Pedestal 3Pedestal 4Pedestal 5

Here is everything Imelda's shopping bag might contain.

  • There are five ways for the bag to hold exactly one pair. Imelda chooses a=ba = b, and there are five such choices.
  • There are two ways for the bag to hold exactly two pairs. She can choose a=3,b=4a = 3, b = 4 (shoes C and D) or a=4,b=5a = 4, b = 5 (shoes D and E).
  • There is one way for the bag to hold exactly three pairs. She chooses a=3,b=5a = 3, b = 5 (shoes C, D and E).

Every other combination breaks Marshall's Law, so there are 88 possibilities in total.

You are her loyal servant, and you must answer her question at any point during the day.

Input

The first line contains a single integer TT, the number of test cases.

The first line of each test case contains two space separated integers NN, the number of pairs of shoes, and QQ, the number of changes the manager makes. The next line contains NN space separated integers p1,p2,,pNp_1, p_2, \dots, p_N, the initial prices.

The next QQ lines describe the changes in chronological order, one per line. Each line has one of the following formats.

  • INC i j k describes an INCREASE operation as explained in the statement.
  • REV i j describes a REVERSE operation as explained in the statement.

Constraints

  • 1T21 \le T \le 2
  • 1N1051 \le N \le 10^5
  • 1Q1051 \le Q \le 10^5
  • 1ijN1 \le i \le j \le N
  • 1k1091 \le k \le 10^9
  • 1pi1091 \le p_i \le 10^9

Output

Every time the manager makes a change, whether to a price or to the order, print a line with a single integer XX. XX is the number of ways Imelda can fill her shopping bag right after that change while obeying Marshall's Law.