AT_abc442_d [ABC442D] Swap and Range Sum
Description
You are given a sequence $ A=(A_1,A_2,\dots,A_N) $ of length $ N $ .
Process $ Q $ queries in order. Each query is in one of the following formats:
- `1 x` : Swap the values of $ A_x $ and $ A_{x+1} $ .
- `2 l r` : Find the value of $ \displaystyle \sum_{l\leq i\leq r} A_i $ .
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ Q $ $ A_1 $ $ A_2 $ $ \dots $ $ A_N $ $ \text{query}_1 $ $ \text{query}_2 $ $ \vdots $ $ \text{query}_Q $
Here, $ \text{query}_i $ represents the $ i $ -th query and is given in one of the following formats:
> $ 1 $ $ x $
> $ 2 $ $ l $ $ r $
Output Format
Let $ q $ be the number of queries of the second type, and output $ q $ lines. The $ i $ -th line $ (1\leq i \leq q) $ should contain the answer to the $ i $ -th query of the second type.
Explanation/Hint
### Sample Explanation 1
- In the $ 1 $ -st query, swap the values of $ A_2 $ and $ A_3 $ . This makes $ A=(2,1,7,8) $ .
- In the $ 2 $ -nd query, find the value of $ A_1+A_2 $ . The answer is $ 2+1=3 $ .
- In the $ 3 $ -rd query, swap the values of $ A_1 $ and $ A_2 $ . This makes $ A=(1,2,7,8) $ .
- In the $ 4 $ -th query, find the value of $ A_2+A_3+A_4 $ . The answer is $ 2+7+8=17 $ .
### Constraints
- $ 2\leq N \leq 2\times 10^5 $
- $ 1\leq Q \leq 5\times 10^5 $
- $ 1\leq A_i \leq 10^4 $
- For queries of the first type, $ 1\leq x \leq N-1 $ .
- For queries of the second type, $ 1\leq l\leq r \leq N $ .
- All input values are integers.