#P9580. 「Cfz Round 1」Wqs Game

    ID: 10353 远端评测题 1200ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>树状数组洛谷原创O2优化线性基洛谷月赛单调栈

「Cfz Round 1」Wqs Game

Background

"Bo" and "Yi" like playing games, and they especially like the wqs weighted game.

Problem Description

The wqs weighted game is played on a sequence {ai}\{a_i\}, with a corresponding 0101 string {bi}\{b_i\}.

  1. If bi=0b_i=0, then the number aia_i belongs to "Bo".
  2. If bi=1b_i=1, then the number aia_i belongs to "Yi".

The rules are: each time, an interval [l,r][l,r] is given. From ala_l to ara_r, the owner of each number decides in order whether to pick it or not. Both players use an optimal strategy.

Because "Bo" is very strong, she yields to "Yi". Therefore, the rule is: if the bitwise XOR sum of the numbers finally chosen by the two players is non-zero, then "Yi" wins; otherwise, "Bo" wins.

Note that each player can see what the other has chosen. A player may choose multiple numbers (as long as the number belongs to them). In the end, compute the total XOR sum of all numbers chosen by both players.

For any interval [l,r][l,r], if "Yi" wins, then w(l,r)=1w(l,r)=1; otherwise, w(l,r)=0w(l,r)=0.

Each query asks for the value of l=LRr=lRw(l,r)\sum\limits_{l=L}^R\sum\limits_{r=l}^Rw(l,r), taken modulo 2322^{32}.

Because the input/output is too large, for test points with tp0tp\ne 0, contestants need to generate the sequence aia_i and query intervals [L,R][L,R] by themselves, and output the answers in a special way.

Note that the correct solution does not depend on the special input/output method.

Input Format

The first line contains three positive integers n,q,tpn,q,tp, representing the length of the sequence, the number of days, the number of games per day, and the input method.

The second line contains a string of length nn, representing the 0101 string {bi}\{b_i\}.

If tp=0tp=0, then the third line contains nn positive integers representing the sequence {ai}\{a_i\}. The next qq lines each contain two positive integers L,RL,R, representing a query for l=LRr=lRw(l,r)\sum\limits_{l=L}^R\sum\limits_{r=l}^Rw(l,r) modulo 2322^{32}.

Otherwise, let the initial value of Sd be tptp, and the initial value of Cnt be 00. First generate aia_i in order using the function GetA, then generate L,RL,R in order using the function GetLR. The specific method is given in the code below.

Output Format

If tp=0tp=0, output qq lines, each containing one positive integer representing the answer to that query.

Otherwise, let ansians_i be the answer to the ii-th query. You need to output the bitwise XOR sum of (ansi×i)mod232(ans_i\times i)\bmod 2^{32}.

3 2 0
100
3 1 2
1 3
2 3
2
0
5 2 0
10100
2 7 6 3 5
1 5
2 4
8
4
20 100 8551679995685981130
11001000000000000000
1673

Hint

Sample Explanation #1

Only w(1,1)=w(1,2)=1w(1,1)=w(1,2)=1.

For the interval [1,3][1,3], if "Yi" chooses the first number, then "Bo" chooses the last two numbers; otherwise, "Bo" chooses nothing, so "Bo" wins.

Note that choices are made from left to right. Before choosing the last two numbers, "Bo" can know whether "Yi" has chosen the first number.

Sample Explanation #2

Only $w(1,1)=w(1,2)=w(1,3)=w(1,4)=w(2,3)=w(2,4)=w(3,3)=w(3,4)=1$.

Sample Explanation #3

Since tp0tp\ne 0 in this sample, you need to use the special input/output method.

Constraints

For all data, $1\le n\le5\times10^5,1\le q\le 1.5\times10^6,0<a_i<2^{60},1\le L\le R\le n,0\le tp<2^{64}$.

Subtask ID Points nn\le qq\le tptp ai<a_i< Special Property
11 66 2020 100100 =0=0 2602^{60} Yes
22 77 100100 10310^3 2102^{10}
33 88 700700 No
44 99 30003000 10510^5 2602^{60}
55 1414 3×1043\times10^4 2202^{20}
66 1717 2×1052\times10^5 1.5×1061.5\times10^6 1\ge1 2602^{60} Yes
77 1919 5×1055\times10^5
88 2020 No

Special Property: in the sequence bib_i, there are at most 1010 zeros.

Notes

Data generation method:

using ul=unsigned long long;
using ui=unsigned int;
ui Ans,ans;
ul Sd,Cnt;
ul Rd(){Sd^=Sd<<19,Sd^=Sd>>12,Sd^=Sd<<29;return Sd^=++Cnt;}
void GetA(ul &a){a=Rd()%((1ull<<60)-2)+1;}
void GetLR(int &l,int &r){
    l=Rd()%n+1,r=Rd()%n+1;
    if(l>r)swap(l,r);
}
int main(){
    //read n,q,tp,b[i]
    if(tp){
        Sd=tp,Cnt=0;
        for(int i=1;i<=n;++i)GetA(a[i]);
        for(int qi=1;qi<=q;++qi){
            GetLR(l,r);
            //sol
            Ans^=ans*qi;
        }
        printf("%u\n",Ans);
	}
}

Translated by ChatGPT 5