#P7780. 「MCOI-Zero / AC6-M01」Invasion of Gracemeria

「MCOI-Zero / AC6-M01」Invasion of Gracemeria

Description

You are given a sequence aa of length nn, initially all 00, and a positive integer kk.

There are qq operations. Each operation gives i,vi, v, meaning to add vv to the suffix a[i,n]a_{[i,n]} of the sequence aa.

After each operation, output the result of the sum of the kk-th powers of the occurrence counts of all values in the sequence, modulo 2005113120051131.

2005113120051131 is a prime number.

Input Format

The first line contains three integers n,q,kn, q, k.

The next qq lines each contain two integers, representing the operation i,vi, v.

Output Format

Output qq lines, each containing one integer: after this operation, the sum of the kk-th powers of the occurrence counts of all values in the sequence, modulo 2005113120051131.

5 5 2
1 1
2 1
3 1
4 1
5 1
25
17
11
7
5

Hint

After the first operation, there are 55 occurrences of 11, so the answer is 52=255^2 = 25.

After the second operation, there are 11 occurrence of 11 and 44 occurrences of 22, so the answer is 12+42=171^2 + 4^2 = 17.

Similarly, the answers are 12+12+32=111^2 + 1^2 + 3^2 = 11, 12+12+12+22=71^2 + 1^2 + 1^2 + 2^2 = 7, and 5×12=55 \times 1^2 = 5.


  • Subtask 1 (20 pts): n,q2×103n, q \leq 2 \times 10^3.
  • Subtask 2 (40 pts): n2×103n \leq 2 \times 10^3.
  • Subtask 3 (40 pts): no special constraints.

For 100%100\% of the testdata, it is guaranteed that 1n,v,k200511301 \leq n, v, k \leq 20051130, 1q5×1051 \leq q \leq 5 \times 10^5, and 1in1 \leq i \leq n.

idea: Sol1, solution: Sol1, code: Sol1, data: Sol1 & Xielan Canxiao (pinyin).

Translated by ChatGPT 5