#P4255. 公主の#18文明游戏

    ID: 2940 远端评测题 1300ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>并查集O2优化素数判断,质数,筛法逆元

公主の#18文明游戏

Description

This game is called “Civil♂ization” (just for laughs), but it’s not the same as the usual meaning.

There are nn cities in the game, numbered 1n1 \sim n, connected by mm undirected roads, numbered 1m1 \sim m.

The system may add NiN_i people to a city XiX_i, and assign these people the belief CiC_i.

The system may also cut a road, given by its road ID XiX_i.

The system may also give a city XiX_i and ask: among all cities reachable from XiX_i, if we select NiN_i people, what is the probability that all of them have belief CiC_i, modulo 1926081719260817.

The input data are not guaranteed to be free of multiple edges and self-loops.

The input data are not guaranteed that the same edge will not be cut more than twice.

Because it is the princess’s game, the input size is large. Please optimize input/output.

Input Format

The first line contains three positive integers n,m,qn, m, q.

The next nn lines each contain two positive integers Ni,CiN_i, C_i, representing the initial population and belief of city ii.

The next mm lines each contain two positive integers Xi,YiX_i, Y_i, representing the endpoints of a road.

The next qq lines each begin with a positive integer optopt (1opt3)(1 \leq opt \leq 3).

  • If opt=1opt = 1, the system adds people: input three integers Xi,Ni,CiX_i, N_i, C_i.
  • If opt=2opt = 2, the system cuts a road: input one integer XiX_i.
  • If opt=3opt = 3, the system asks for a probability: input three integers Xi,Ni,CiX_i, N_i, C_i.

Output Format

For each operation with opt=3opt = 3, output one line with one integer.

5 5 5
5 1
9 2
8 1
8 1
6 2
5 2
1 2
2 2
1 1
5 3
1 1 3 2
2 1
3 3 4 1
3 2 3 1
3 1 2 1

9293681
15578602
849742

Hint

Complaining that someone didn’t tell me I forgot to include a sample.

Supplementing a sample (I actually had one).

Apologies to everyone.

Constraints:

  • For 30%30\% of the testdata, 1n,m,q1001 \leq n, m, q \leq 100.
  • For 60%60\% of the testdata, 1n,m,q500001 \leq n, m, q \leq 50000.
  • For 100%100\% of the testdata, 1n,m,q4000001 \leq n, m, q \leq 400000.
  • For 100%100\% of the testdata, all beliefs fit within C++ int and Pascal long int.
  • For 100%100\% of the testdata, each addition size and each initial population do not exceed 1010.
  • For 100%100\% of the testdata, the testdata are randomly generated.

Problem by @玫葵之蝶.

Translated by ChatGPT 5