Main topic
Now, give you two digits forn and m two binary numbers a,b Now, let's do the following:
- Calculate a&b
- The answer accumulates the value of the previous action
- BBB, move right one, the last one to abandon directly
Now, please figure out the final answer, and output the answer to 998244353 modulo
Input and output format: input format:
First row, two integers n , m , (1≤n,m≤2x105)
First line, a binary number a with a length of n
First line, a binary number b with a length of M
Output format:
A line, a number, that represents the answer
Ideas:
Because the first binary number is not moving, the second one is moving, so we can get the answer by preprocessing the first number.
Because it is with, so only two of them are only 1 o'clock will have the answer to the contribution
So, let's say this example:
1001
11010
He's going to have some of the following.
01001
11010
1001
1101
1001
0110
1001
0011
1001
0001
We will find that the first 1 differences and the first 1 above and the last 1 XOR each other and contribute to the answer.
So the 1 contribution to the answer is 8+1=9 .
Let's spread this rule.
Each of the 1 in Y is done as above
You can come up with answers
However, we will find that the complexity of the answer is O (nxm) .
So we're going to preprocess
Use the prefix and run x again
Complexity optimization to O (m+n)
Code:
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#defineRii Register int i#defineRij Register Int J#defineP 998244353#defineint long Longusing namespacestd;intb;intx[200005],y[200005],bs[200005],qzh[200005];voidYcl () {bs[0]=1; for(rii=1; i<=200002; i++) {Bs[i]=bs[i-1]*2; Bs[i]%=p; }}signed Main () {scanf ("%lld%lld\n",&a,&b); for(rii=1; i<=a;i++) {X[i]=getchar ()-'0'; } getchar (); for(rii=1; i<=b;i++) {Y[i]=getchar ()-'0'; } YCL (); for(rii=a;i>=1; i--) {Qzh[a-i+1]=qzh[a-i]; Qzh[a-i+1]+=x[i]*bs[a-i]; Qzh[a-i+1]%=p; } if(b>a) { for(rii=a+1; i<=b;i++) {Qzh[i]=qzh[i-1]; } }//For (rii=1;i<=b;i++)// {//printf ("%d", Qzh[i]);// } intans=0; for(rii=1; i<=b;i++) {ans+=y[i]*qzh[b-i+1]; Ans%=p; } cout<<ans%p;}
Cf1066ebinary Numbers and Sum (prefix and, binary)