#P10890. 【烂题杯 Round 1】可持久化糖果树

    ID: 12320 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>多项式O2优化容斥原理快速沃尔什变换 FWT单位根反演

【烂题杯 Round 1】可持久化糖果树

Problem Description

Xiao A has a candy tree with nn nodes, numbered 1,2,,n1,2,\cdots,n. In each node, there are mm children, numbered 1,2,,m1,2,\cdots,m. Each child can make kk wishes, numbered 1,2,,k1,2,\cdots,k. For the xx-th wish of the jj-th child in node ii, the child can get ai,j,xa_{i,j,x} candies. We call the candy tree that has not been modified version 00.

A child is called happy if and only if, after making kk rounds of wishes, the total number of candies she can get is divisible by 33, so that the candies can be evenly shared among her and her parents. That is, the jj-th child in node ii is happy if and only if x=1kai,j,xmod3=0\sum_{x=1}^k a_{i,j,x}\bmod 3=0.

A node is called joyful if and only if all the mm children in it are happy.

Xiao A can cast magic: he will perform qq modifications, indexed from 11. The ii-th modification is described by (x,y,z)(x,y,z), meaning that in version xx of the tree, for all nodes and all children, the number of candies obtained from the yy-th wish is multiplied by zz, producing version ii of the tree. You are required to output how many nodes are joyful in each version of the tree.

Input Format

The first line contains 33 integers nn, mm, and kk, representing the number of nodes, the number of children in each node, and the number of wishes per child.

Then read nn lines, each containing m×km\times k integers, representing ai,j,xa_{i,j,x}, indexed starting from 11.

Then one line contains a positive integer qq, representing the number of modifications.

Then read qq lines. The ii-th line contains three positive integers x,y,zx,y,z, meaning that in version xx of the tree, for all nodes and all children, the number of candies obtained from the yy-th wish is multiplied by zz, producing version ii of the tree, indexed starting from 11.

Output Format

Output q+1q+1 lines, each containing a positive integer. The ii-th line denotes the number of joyful nodes in version i1i-1 of the tree.

2 2 3
1 2 3 4 5 6
7 8 9 10 11 12
5
0 1 13
0 2 14
1 2 15
1 3 16
2 3 17
2
2
0
0
2
0
10 1 2
568508003 500481779
296073373 42467215
878878423 182698953
810051825 300278778
506619835 300576052
878109763 816209514
722729481 557555287
810227870 524124026
693592304 92818139
971977946 139368888
3
0 1 524124026
0 1 500481779
0 2 816209514
1
6
6
2

Hint

Constraints:

For 0%0\% of the testdata, n103n\le 10^3, q103q\le 10^3.

For 0%0\% of the testdata, n103n\le 10^3, q106q\le 10^6.

For another 0%0\% of the testdata, m=1m=1.

For another 0%0\% of the testdata, k=1k=1.

For another 0%0\% of the testdata, q=0q=0.

For 100%100\% of the testdata, 1n1051\le n\le 10^5, 1m41\le m\le 4, 1k121\le k\le 12, 0q1060\le q\le 10^6, 0ai,j,x1090\le a_{i,j,x}\le 10^9. For the ii-th modification, 0x<i0\le x<i, 1yk1\le y\le k, 0z1090\le z\le 10^9.

The input and output are large, so a fast I/O method is required.

Translated by ChatGPT 5