#P8323. 『JROI-4』傀影与猩红孤钻

『JROI-4』傀影与猩红孤钻

Description

We provide a formal statement at the bottom of the Description. If you do not want to read the roleplay part, you can directly jump to the bottom of the Description.

God retrieved a part of His power during the exploration of the Crimson Troupe. Not much, but enough.

God met Phantom, and prepared to judge him with Brilliant Shards.

However, Phantom hid in a DAG that is divided into dd layers.

Specifically, nodes in layer ii of the DAG only have edges pointing to nodes in layer i+1i+1.

“Then I will keep playing with you,” God thought.

God decided on a way to carry out the judgment.

Specifically, God initially has some Brilliant Shards. God believes that polynomials have great power, so Brilliant Shards are polynomials. I am not telling you it is because I am too lazy to make up the story.

God has three operations on Brilliant Shards:

  1. “No Degree”

It can make a Brilliant Shard stronger. Specifically, applying this operation to F(x)F(x) is equivalent to setting F(x)=F2(x)F(x)=F^2(x).

  1. “Continuation of Civilization”

It can make the Brilliant Shard after “No Degree” even stronger. Specifically, applying this operation to F(x)F(x) is equivalent to setting F(x)=F(x2)F(x)=F(x^2).

  1. “Night Terror”

It can merge two Brilliant Shards and make them stronger. Specifically, applying this operation to F(x)F(x) and G(x)G(x) returns a polynomial F(x)+G(x)F(x)+G(x).

God judges Phantom in the following way:

Place Brilliant Shards on the nodes in the first layer.

Before a Brilliant Shard enters a node, it applies “No Degree” to itself.

When two Brilliant Shards meet, apply “Night Terror” to these two Brilliant Shards. Only one Brilliant Shard remains, which is the result of applying “Night Terror” to the two.

A Brilliant Shard will only leave a node after Brilliant Shards have passed through all edges connected to that node. When a Brilliant Shard leaves a node, it applies “Continuation of Civilization,” then splits into several Brilliant Shards identical to the original one, leaving one Brilliant Shard at that node. Then, each edge will be passed through by exactly one Brilliant Shard.

If Phantom is at node uu, and God has an execution points (EXP) kk, and the Brilliant Shard left at that node is Fu(x)F_u(x), then Phantom will be struck by an electric current of Fu(k)F_u(k) volts.

Now God has some queries. Each query is like: if Phantom is hiding at node uu, and the execution points is kk, then how many volts of current will Phantom receive?

God is merciful. The answer may be too large, so you only need to output the result modulo 7340033(220×7+1)7340033(2^{20}\times7+1) (a prime).

Formal Statement

You are given a DAG divided into dd layers. Each node has a polynomial Fu(x)F_u(x). There may be multiple edges.

In this DAG, nodes in layer ii only have edges to nodes in layer i+1i+1.

Let SuS_u contain all nodes that have edges pointing to node uu. Then it holds that Fu(x)=vSuFv2(x2)F_u(x)=\sum_{v \in S_u}F_v^2(x^2).

You are given the polynomials of the nodes in the first layer. Each query gives u,ku,k, and asks for Fu(k)F_u(k) modulo 7340033(220×7+1)7340033(2^{20}\times7+1) (a prime).

Please note that multiple edges count as one edge.

Input Format

The first line contains an integer dd, representing the number of layers of the DAG.

The next line contains dd integers. The ii-th number nin_i indicates that there are nin_i nodes in layer ii.

The next n1n_1 lines describe the polynomials of the nodes in the first layer. In the ii-th line, there are several numbers representing the polynomial of node ii in the first layer.

Specifically, the first number in each line is pp, the highest degree of the polynomial. The next p+1p+1 numbers are the coefficients of the polynomial. If the ii-th of these numbers (excluding pp) is fi1f_{i-1}, then the polynomial is i=0pfixi\sum_{i=0}^pf_ix^i.

The remaining input is divided into dd blocks. At the beginning of block ii, there are two numbers m,qm,q, meaning there are mm edges from layer ii, and God has qq queries among the nodes in layer ii.

The next mm lines each contain two numbers u,vu,v, indicating that the node numbered uu in layer ii connects to the node numbered vv in layer i+1i+1.

The next qq lines each contain two integers u,ku,k, indicating that God asks: when Phantom is at node uu in layer ii, and the execution points is kk, output the volts of current Phantom receives modulo 73400337340033.

Output Format

Since the output may be too large, you need to encrypt the output.

Specifically, for the queries in layer kk, if the answer to the ii-th query is aia_i, you only need to output $(k \times \bigoplus_{i=1}^q(q-i) \times a_i)\bmod 2^{32}$.

Note that there are exactly dd lines of output, one number per line.

3
1 2 2
1 1 1

2 1
1 1
1 2
1 3

3 2
1 1
1 2
2 2
2 5
1 36

0 2
1 7
2 6
0
1352
10488222
//下面是加密前的输出
4
676
1682209
3496074
4354184

Hint

  • Subtask 1 (7 pts): 1d21\leq d\leq 2.
  • Subtask 2 (20 pts): 1d10,q=11\leq d\leq 10,\sum q=1.
  • Subtask 3 (13 pts): n1=2n_1=2, and the time limit is 5 s.
  • Subtask 4 (60 pts): no special restrictions.
  • Subtask 5 (0 pts): hack testdata.

For 100%100\% of the testdata, 1n<50601\leq\sum n<5060, 1d101\leq d\leq 10, q1.5×106\sum q\leq 1.5 \times 10^6, 1w,k<73400331\leq w,k<7340033, 0p20 \leq p \leq 2.

If layer ii has mim_i edges, then for idi\neq d it is guaranteed that ni<ni+12×nin_i<n_{i+1}\leq2\times n_i and nimi3×nin_i\leq m_i\leq 3\times n_i, and md=0,1n15m_d=0,1 \leq n_1 \leq 5.

Translated by ChatGPT 5