PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SRD0000056. Đảo ngược và tổng đoạn (Reversals and Sums)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đảo ngược và tổng đoạn (Reversals and Sums)
Reversals and Sums
Source: VNOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given a sequence of nonnegative integers, process queries on inclusive, one-indexed ranges:
1 l r: reverse the order of elements within .2 l r: print the current sum of elements within .
Every reversal affects all subsequent operations; sequence positions are dynamic.
Input
The first line contains ; the next line has the values. Each subsequent operation is t l r, with and .
Output
Print a sum for each type-2 query.
Subtasks
- Subtask 1 (10 points): ; . One-based, inclusive intervals.
- Subtask 2 (20 points): ; . One-based, inclusive intervals.
- Subtask 3 (30 points): ; . One-based, inclusive intervals.
- Subtask 4 (40 points): ; . One-based, inclusive intervals.
Examples
Input
8 3
2 1 3 4 5 3 4 4
2 2 4
1 3 6
2 2 4
Output
8
9
Explanation
Initially the array is , so the sum on is . Reversing gives , and the next sum on is .