Mystical Numbers Codechef Solution | May CHALLENGE

Codechef
Share:

Mystical Numbers Codechef Solution

A number MM is said to be a Mystical Number with respect to a number XX if (M⊕X)>(M&X)(M⊕X)>(M&X).

You are given an array AA of size NN. You are also given QQ queries. Each query consists of three integers LL, RR, and XX.

For each query, find the count of Mystical Numbers in the subarray A[L:R]A[L:R] with respect to the number XX.

Notes:

  • ⊕⊕ represents the Bitwise XOR operation and && represents the Bitwise AND operation.
  • A[L:R]A[L:R] denotes the subarray A[L],A[L+1],…,A[R]A[L],A[L+1],…,A[R].

Input Format

  • The first line contains a single integer TT – the number of test cases. Then the test cases follow.
  • The first line of each test case contains an integer NN – the size of the array AA.
  • The second line of each test case contains NN space-separated integers A1,A2,…,ANA1,A2,…,AN denoting the array AA.
  • The third line of each test case contains an integer QQ – denoting the number of queries.
  • The ithith of the next QQ lines contains three space-separated integers LL , RR and XX.

Output Format

For each testcase,

  • For each query, print in a new line, the count of Mystical Numbers among A[L],A[L+1],…,A[R]A[L],A[L+1],…,A[R] with respect to the number XX.

Constraints

  • 1≤T≤1001≤T≤100
  • 1≤N≤2⋅1051≤N≤2⋅105
  • 0≤Ai<2310≤Ai<231
  • 1≤Q≤2⋅1051≤Q≤2⋅105
  • 1≤L≤R≤N1≤L≤R≤N
  • 0≤X<2310≤X<231
  • Sum of NN over all test cases does not exceed 2⋅1052⋅105.
  • Sum of QQ over all test cases does not exceed 2⋅1052⋅105.

Sample Input 1 

1
5
1 2 3 4 5
2
1 5 4
2 5 2

Sample Output 1 

3
2

Explanation

Test case 11:

  • Query 11: L=1,R=5,X=4L=1,R=5,X=4.
    • A1⊕X=5,A1&X=0A1⊕X=5,A1&X=0.
    • A2⊕X=6,A2&X=0A2⊕X=6,A2&X=0.
    • A3⊕X=7,A3&X=0A3⊕X=7,A3&X=0.
    • A4⊕X=0,A4&X=4A4⊕X=0,A4&X=4.
    • A5⊕X=1,A5&X=4A5⊕X=1,A5&X=4.

Mystical numbers are A1,A2,A1,A2, and A3A3 with respect to 44. Therefore, the answer to this query is 33.

  • Query 22: L=2,R=5,X=2L=2,R=5,X=2.
    • A2⊕X=0,A2&X=2A2⊕X=0,A2&X=2.
    • A3⊕X=1,A3&X=2A3⊕X=1,A3&X=2.
    • A4⊕X=6,A4&X=0A4⊕X=6,A4&X=0.
    • A5⊕X=7,A5&X=0A5⊕X=7,A5&X=0.

Mystical numbers are A4A4 and A5A5 with respect to 22. Therefore , the answer to this query is 22.

Mystical Numbers Codechef  SOLUTION

Download Code
login to google play console, youtube video search by image, how to add a google account, which are the google apps, what is the google app, how to add a new google account, all the google apps, which service is the part of google, adsetting google, google data studio, google DNS, GCP console, bigquery, google studio, google api console, google app engine, anthos, google apis, google public DNS, google audio, google launcher, gcloud console, google compute engine, google webmaster console, google logged-in devices, gdrive unlimited,google console tools,google studio login,my google voice,hey google service,find similar images google, my google forms, www google com bd search, search using images in google,google image search scan,google sea console,website console google, google sound, gdrive storage for students, google site console, google console login, webmaster console, searc h console, google server down, google backup login, photo finder google, google products and services, google console tool, google image check, google cloud search is used for, google dashboard studio, google voice and audio activity,gcp dashboards, google services down, google go app, google dns down, google image identifier,check picture on google,google new launcher,google image finder online,image check google google google go, image finder on google, finding images on google, photo find google, find a picture in google, find the photo on google, picture find google, image find on google, find with photo google, image finder google online, google find with image, photo finder in google, google find image search, search using image in google, search on google with image, google server down today, google server down news

Read More Post Here

Leave a Comment

Your email address will not be published. Required fields are marked *

x