Subarray XOR Codechef Solution | MARCH CHALLENGE

Thunder Bitz
2 min readMar 11, 2022
Subarray XOR Codechef Solution | MARCH CHALLENGE

Subarray XOR CodeChef Solution:

Mary loves binary strings.
Given a binary string SS, she defines the beauty of the string as the bitwise XOR of decimal representations of all substrings of SS.

Find the beauty of string SS. Since the answer can be huge, print it modulo 998244353998244353.

For example, the decimal representation of binary string 11011101 is 1⋅23+1⋅22+0⋅21+1⋅20=8+4+0+1=131⋅23+1⋅22+0⋅21+1⋅20=8+4+0+1=13. Kindly refer sample explanation for more such examples.

A string AA is a substring of a string BB if AA can be obtained from BB by deleting several (possibly zero) characters from the beginning and several (possibly zero) characters from the end.

Input Format

- The first line of input contains a single integer TT, denoting the number of test cases. The description of test cases follow.

- First line of each test case contains one integer NN — the length of the binary string.

- Second line of each test case contains the binary string SS.

Output Format

For each test case, output in a single line, beauty of the string modulo 998244353998244353.

Constraints

- 1≤T≤1001≤T≤100

- 1≤N≤1051≤N≤105

- Sum of NN over all test cases does not exceed 2⋅1052⋅105

Sample Input 1

3

2

10

3

101

4

1111

Sample Output 1

3

6

12

Explanation

Test Case 11: All substrings of the string S=10S=10 are . The decimal representation of these substrings is denoted by the array . Bitwise XOR of all these values is 1⊕0⊕2=31⊕0⊕2=3.

Test Case 22: All substrings of the string S=101S=101 are . The decimal representation of these substrings is denoted by the array . Bitwise XOR of all these values is: 1⊕0⊕1⊕2⊕1⊕5=61⊕0⊕1⊕2⊕1⊕5=6.

Test Case 33: All substrings of the string S=1111S=1111 are . The decimal representation of these substrings is denoted by the array . Bitwise XOR of all these values is: 1⊕1⊕1⊕1⊕3⊕3⊕3⊕7⊕7⊕15=121⊕1⊕1⊕1⊕3⊕3⊕3⊕7⊕7⊕15=12.

Subarray XOR Codechef SOLUTION

C++

Join our telegram group for codes.

Java

Will be Updated soon

Python

Will be Updated soon

Read More Post Here

--

--