PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000055. Đảo đoạn và tính tổng (Range Reverse Range Sum)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đảo đoạn và tính tổng (Range Reverse Range Sum)

Range Reverse Range Sum

Source: Library Checker

Version: Phuoc Hung OJ Extended

Problem Statement

Given a sequence of nonnegative integers a0,…,aN−1a_0,\ldots,a_{N-1}, process QQ operations on half-open ranges [l,r)[l,r):

  • 0 l r: reverse the order of elements al,…,ar−1a_l,\ldots,a_{r-1}.
  • 1 l r: print ∑i=lr−1ai\sum_{i=l}^{r-1}a_i.

Indices start at 00; empty ranges (l=rl=r) are valid and have sum zero. The array may be empty (N=0N=0).

Input

The first line contains N,QN,Q, followed by the NN values (none if N=0N=0). Each of the next QQ lines is t l r with t∈{0,1}t\in\{0,1\} and 0≤l≤r≤N0\le l\le r\le N.

Output

Print one sum per type-1 operation.

Subtasks

  • Subtask 1 (10 points): 0≤n≤600\le n\le60; 0≤q≤1000\le q\le100. Zero-based, half-open [l,r)[l,r) intervals, allowing l=rl=r.
  • Subtask 2 (20 points): 0≤n≤20000\le n\le2000; 0≤q≤30000\le q\le3000. Zero-based, half-open [l,r)[l,r) intervals, allowing l=rl=r.
  • Subtask 3 (30 points): 0≤n≤300000\le n\le30000; 0≤q≤300000\le q\le30000. Zero-based, half-open [l,r)[l,r) intervals, allowing l=rl=r.
  • Subtask 4 (40 points): 0≤n≤2000000\le n\le200000; 0≤q≤2000000\le q\le200000. Zero-based, half-open [l,r)[l,r) intervals, allowing l=rl=r.

Examples

Input

4 5
1 2 3 4
1 1 3
0 2 4
1 0 3
0 4 4
1 0 0

Output

5
7
0

Explanation

Initially the sequence is (1,2,3,4)(1,2,3,4). Query 1 1 3 sums 2+3=52+3=5. Reversing 0 2 4 gives (1,2,4,3)(1,2,4,3), then 1 0 3 sums 1+2+4=71+2+4=7. The final empty-range sum is 0.