GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Friday 6 May 2022

Mystical Numbers CodeChef Solution | CodeChef Problem Solution 2022

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

You are given an array A of size N. You are also given Q queries. Each query consists of three integers LR, and X.

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

Solution Click Below:-  CLICK HERE

Notes:

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

Input Format

  • The first line contains a single integer T - the number of test cases. Then the test cases follow.
  • The first line of each test case contains an integer N - the size of the array A.

  • The second line of each test case contains N space-separated integers A1,A2,,AN denoting the array A.
  • The third line of each test case contains an integer Q - denoting the number of queries.
  • The ith of the next Q lines contains three space-separated integers L , R and X.

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] with respect to the number X.

Constraints

  • 1T100
  • 1N2105
  • 0Ai<231
  • 1Q2105
  • 1LRN
  • 0X<231
  • Sum of N over all test cases does not exceed 2105.
  • Sum of Q over all test cases does not exceed 2105.

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 1:

  • Query 1L=1,R=5,X=4.
    • A1X=5,A1&X=0.
    • A2X=6,A2&X=0.
    • A3X=7,A3&X=0.
    • A4X=0,A4&X=4.
    • A5X=1,A5&X=4.

Mystical numbers are A1,A2, and A3 with respect to 4. Therefore, the answer to this query is 3.

  • Query 2L=2,R=5,X=2.
    • A2X=0,A2&X=2.
    • A3X=1,A3&X=2.
    • A4X=6,A4&X=0.
    • A5X=7,A5&X=0.

Mystical numbers are A4 and A5 with respect to 2. Therefore , the answer to this query is 2.

Join Now for Solution:- 

No comments:

Post a Comment