PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SRD0000043. Marisa is happy
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Marisa is happy
Marisa is happy
Source: MarisaOJ
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a permutation of and an array initially containing all zeros. The same array is accessed either in natural index order or in permutation order. Process:
0 l r x: add to .1 l r x: add to .2 l r: output .3 l r: output .
Both coordinate systems access one shared array, so updates in either order affect both query types.
Input
The first line contains , the next a permutation of , then exactly operation lines of the four types above.
Output
Print one 64-bit sum for each operation of type 2 or 3.
Subtasks
- Subtask 1 (15 points): The limits are ; every operation type is permitted.
- Subtask 2 (15 points): Only operation types
1and3occur; . - Subtask 3 (15 points): At most 2 operations of type
2or3combined occur in the whole input; . - Subtask 4 (15 points): For each operation type, all its appearances use the same pair ; .
- Subtask 5 (40 points): Queries can be of any of the four types; .
Examples
Input
5 6
3 1 5 4 2
0 2 4 2
1 2 4 3
2 3 4
0 2 5 1
3 2 4
3 1 3
Output
7
13
10
Explanation
For , the first update adds to natural indices , and the next adds at indices . The natural sum on positions becomes . Subsequent operations produce permutation-order sums and .