CF1707F.Bugaboo

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A transformation of an array of positive integers a1,a2,,ana_1,a_2,\dots,a_n is defined by replacing aa with the array b1,b2,,bnb_1,b_2,\dots,b_n given by bi=aia(imodn)+1b_i=a_i\oplus a_{(i\bmod n)+1} , where \oplus denotes the bitwise XOR operation.

You are given integers nn , tt , and ww . We consider an array c1,c2,,cnc_1,c_2,\dots,c_n ( 0ci2w10 \le c_i \le 2^w-1 ) to be bugaboo if and only if there exists an array a1,a2,,ana_1,a_2,\dots,a_n such that after transforming aa for tt times, aa becomes cc .

For example, when n=6n=6 , t=2t=2 , w=2w=2 , then the array [3,2,1,0,2,2][3,2,1,0,2,2] is bugaboo because it can be given by transforming the array [2,3,1,1,0,1][2,3,1,1,0,1] for 22 times:

$$ [2,3,1,1,0,1]\to [2\oplus 3,3\oplus 1,1\oplus 1,1\oplus 0,0\oplus 1,1\oplus 2]=[1,2,0,1,1,3]; \\ [1,2,0,1,1,3]\to [1\oplus 2,2\oplus 0,0\oplus 1,1\oplus 1,1\oplus 3,3\oplus 1]=[3,2,1,0,2,2]. $$ </p><p>And the array $\[4,4,4,4,0,0\]$ is not bugaboo because $4 > 2^2 - 1$ . The array $\[2,3,3,3,3,3\]$ is also not bugaboo because it can't be given by transforming one array for $2$ times.</p><p>You are given an array $c$ with some positions lost (only $m$ positions are known at first and the remaining positions are lost). And there are $q$ modifications, where each modification is changing a position of $c$ . A modification can possibly change whether the position is lost or known, and it can possibly redefine a position that is already given.</p><p>You need to calculate how many possible arrays $c$ (with arbitrary elements on the lost positions) are bugaboos after each modification. Output the $i$ -th answer modulo $p\_i$ ( $p\_i$ is a given array consisting of $q$$$ elements).

输入格式

The first line contains four integers nn , mm , tt and ww ( 2n1072\le n\le 10^7 , 0mmin(n,105)0\le m\le \min(n, 10^5) , 1t1091\le t\le 10^9 , 1w301\le w\le 30 ).

The ii -th line of the following mm lines contains two integers did_i and eie_i ( 1din1\le d_i\le n , 0ei<2w0\le e_i< 2^w ). It means the position did_i of the array cc is given and cdi=eic_{d_i}=e_i . It is guaranteed that 1d1<d2<<dmn1\le d_1<d_2<\ldots<d_m\le n .

The next line contains only one number qq ( 1q1051\le q\le 10^5 ) — the number of modifications.

The ii -th line of the following qq lines contains three integers fif_i , gig_i , pip_i ( 1fin1\le f_i\le n , 1gi<2w-1\le g_i< 2^w , 11pi109+711\le p_i\le 10^9+7 ). The value gi=1g_i=-1 means changing the position fif_i of the array cc to a lost position, otherwise it means changing the position fif_i of the array cc to a known position, and cfi=gic_{f_i}=g_i . The value pip_i means you need to output the ii -th answer modulo pip_i .

输出格式

The output contains qq lines, denoting your answers.

输入输出样例

  • 输入#1

    3 2 1 1
    1 1
    3 1
    4
    2 0 123456789
    2 1 111111111
    1 -1 987654321
    3 -1 555555555

    输出#1

    1
    0
    1
    2
  • 输入#2

    24 8 5 4
    4 4
    6 12
    8 12
    15 11
    16 7
    20 2
    21 9
    22 12
    13
    2 13 11
    3 15 12
    5 7 13
    9 3 14
    10 5 15
    11 15 16
    13 14 17
    14 1 18
    18 9 19
    19 6 20
    23 10 21
    24 8 22
    21 13 23

    输出#2

    1
    4
    9
    2
    1
    0
    1
    10
    11
    16
    16
    0
    16

说明/提示

In the first example, n=3n=3 , t=1t=1 , and w=1w=1 . Let ?? denote a lost position of cc .

In the first query, c=[1,0,1]c=[1,0,1] . The only possible array [1,0,1][1,0,1] is bugaboo because it can be given by transforming [0,1,1][0,1,1] once. So the answer is 1mod123456789=11\bmod 123\,456\,789 = 1 .

In the second query, c=[1,1,1]c=[1,1,1] . The only possible array [1,1,1][1,1,1] is not bugaboo. So the answer is 0mod111111111=00\bmod 111\,111\,111 = 0 .

In the third query, c=[?,1,1]c=[?,1,1] . There are two possible arrays [1,1,1][1,1,1] and [0,1,1][0,1,1] . Only [0,1,1][0,1,1] is bugaboo because it can be given by transforming [1,1,0][1,1,0] once. So the answer is 1mod987654321=11\bmod 987\,654\,321=1 .

In the fourth query, c=[?,1,?]c=[?,1,?] . There are four possible arrays. [0,1,1][0,1,1] and [1,1,0][1,1,0] are bugaboos. [1,1,0][1,1,0] can be given by performing [1,0,1][1,0,1] once. So the answer is 2mod555555555=22\bmod 555\,555\,555=2 .

首页