PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SRD0000105. Tổng trên các tập chỉ số (Subset 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
Tổng trên các tập chỉ số (Subset Sums)
Subset Sums
Source: Codeforces Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of integers and sets of indices . Each set contains distinct positions between and . Different sets may overlap.
Process operations in the given order:
? k: Print the sum using the current array values.+ k x: For every position , replace by . All other positions remain unchanged. The integer may be negative or zero.
All updates persist. If a position belongs to several sets, an update to a given set changes that position exactly once.
Input
- Line 1: integers
n m q. - Line 2: integers .
- Each of the next lines begins with a positive integer , followed by distinct indices belonging to set .
- The final lines contain either
? kor+ k x.
Output
For each ? k operation, output the requested sum on its own line in query order. The answer may be negative and may exceed the 32-bit signed integer range.
Subtasks
- Subtask 1 (15 points): , , , sum of set sizes at most ; , distinct indices within each set; .
- Subtask 2 (20 points): , , , sum of set sizes at most ; , distinct indices within each set; .
- Subtask 3 (25 points): , , , sum of set sizes at most ; , distinct indices within each set; .
- Subtask 4 (40 points): , , , sum of set sizes at most ; , distinct indices within each set; .
Examples
Input
5 3 5
5 -5 5 1 -4
2 1 2
4 2 1 4 5
2 2 5
? 2
+ 3 4
? 1
+ 2 1
? 2
Output
-3
4
9
Explanation
Initially, has sum . Operation + 3 4 increases and to and , so the sum of becomes . Finally, + 2 1 increments the four positions in , giving the sum .