#P10680. [COTS 2024] 双双决斗 Dvoboj

    ID: 12175 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2024O2优化ST 表COCI(克罗地亚)根号分治

[COTS 2024] 双双决斗 Dvoboj

Background

Translated from Izborne Pripreme 2024 (Croatian IOI/CEOI Team Selection) D1T1. 2s,1G\texttt{2s,1G}.

Two pharaonic yellow lines turned into an eye...

Problem Description

Jusuf has NN cards, numbered from 11 to NN from left to right. The power of the ii-th card is pip_i. Since Jusuf is about to take part in a contest, he wants to imagine battles in his mind. Sometimes, he also changes the power values of the cards. In total, Jusuf will perform QQ operations, and each operation is one of the following two types:

  1. 1 i r: Jusuf sets the power of the card at position ii to rr, i.e. pirp_i\gets r.

  2. 2 l k: Jusuf imagines a battle in his mind. This battle uses 2k2^k cards from the ll-th card to the (l+2k1)(l + 2^k - 1)-th card, i.e. cards l,l+1,,l+2k1l,l+1,\cdots,l + 2^k − 1.

    The battle will last for kk rounds. In each round, Jusuf groups the (2i1)(2i-1)-th and the 2i2i-th cards together (for example, the 11-st and the 22-nd cards form a group).

    For each group of cards, Jusuf compares their powers. Suppose the powers of the two cards are AA and BB. The card with the larger power wins, and the winning card’s power becomes AB|A − B|, while the other card is removed. In particular, if A=BA=B, then the result of this battle cannot be determined: one card will win at random, and its power becomes 00.

    Note that after kk rounds, only one card will remain. Jusuf wants to know the power of this remaining card.

Since Jusuf is only imagining the battle, the number of cards will not actually change, and pip_i will not change either.

Input Format

The first line contains two positive integers N,QN,Q, as described in the statement.

The second line contains NN integers. The ii-th integer represents pip_i.

The next QQ lines each contain 33 positive integers, describing an operation.

Output Format

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

5 3
4 8 2 0 7
2 1 2
1 1 9
2 2 1
2
6
8 6
1 2 3 4 5 6 7 8
2 1 3
1 4 1
1 7 3
2 1 3
1 2 100
2 2 2
0
3
93
9 5
1 0 2 0 4 1 3 2 8
2 2 3
2 1 3
1 5 1
1 6 4
2 4 2
2
1
0

Hint

Sample Explanation

For the first query of sample 11, we have:

$$(\bold{\textcolor{red}{4}},8,\bold{\textcolor{red}{2}},0)\to (\bold{\textcolor{red}{4}},2)\to(2)$$

For the second query of sample 11, we have:

(8,2)(6)(\bold{\textcolor{red}{8}},2)\to(6)

Constraints

For 100%100\% of the testdata, it is guaranteed that:

  • 2N2000002\le N\le 200\, 000, 1Q2000001\le Q\le 200\, 000
  • 0pi1090\le p_i\le 10^9
  • 1iN1\le i\le N, 0r1090\le r\le 10^9
  • 1lN1\le l\le N, 1l+2k1N1\le l+{2^k}-1\le N
Subtask ID Points Constraints
11 1111 N,Q1000N, Q \leq 1000
22 1313 N=2kN=2^k
33 1616 0pi,r10\le p_i,r\le 1
44 1717 No modification operations
55 4343 No additional constraints

Translated by ChatGPT 5