#SRD0000014. Bài toán phần dư (Remainder Problem)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bài toán phần dư (Remainder Problem)
Remainder Problem
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Consider an array containing exactly elements, indexed from to . Initially, all . Process operations in order:
1 x y: Add integer (possibly negative or zero) to .2 x y: Calculate the sum of all such that and .
In type-2 queries, is the modulus and the remainder, with . If , only positive multiples of are included; index is not part of the array. Each query observes all preceding updates.
Input
The first line contains . Each of the next lines is t x y, where . For , is an index and an increment. For , is a modulus and a remainder.
Output
For every type-2 query, print the sum of array values at indices belonging to the specified residue class. Negative answers are allowed.
Subtasks
- Subtask 1 (10 points): ; mảng có phần tử. Với loại
1: , . Với loại2: , . Bảo đảm có ít nhất một thao tác loại2. - Subtask 2 (20 points): ; mảng có phần tử. Với loại
1: , . Với loại2: , . Bảo đảm có ít nhất một thao tác loại2. - Subtask 3 (30 points): ; mảng có phần tử. Với loại
1: , . Với loại2: , . Bảo đảm có ít nhất một thao tác loại2. - Subtask 4 (40 points): ; mảng có phần tử. Với loại
1: , . Với loại2: , . Bảo đảm có ít nhất một thao tác loại2.
Examples
Input
5
1 3 4
2 3 0
2 4 3
1 4 -4
2 1 0
Output
4
4
0
Explanation
After 1 3 4, only . The indices congruent to modulo are and sum to . The indices congruent to modulo are and also sum to . After adding at index , the sum over all positive indices (remainder modulo ) is .