Binod Codechef solutions Today | Codechef Starters 65✅ (100/100) FULL | AC Code ✅| BIN_OD

IF ANYONE DONE THIS AND IS YOU WANT TO HELP SO JUST WRITE DOWN CODE IN COMMENTS

For Solution

Coming Soon After 10 Minutes

#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int n;
int q;
cin>>n>>q;
int
for(int
long long x;
cin>>x;
for(int j=0;j<64;j++){
for(int i=0;i<64;i++){
int count=0;
for(int
count+=a[i][j];
a[i][j]=count;
int 11
cin>>k>>ll >>rl >>12>>r2;
int totalf=rl -11+1 ;
int totals=r2-12+1 ;
int totalfo:
int totalso;
else
else
long sum = (long)(totalf-totalfo)*(long)(totalso) + (long
(totalfo)*(long)(totals-totalso);
cout<<sum<<endl;
return 0;

Problem

A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.

You are given an array A of N elements. Process Q queries on this array, of the following form:

  • Each query contains 5 integers k, L_1, R_1, L_2, R_2. It is guaranteed that L_1 \leq R_1 \lt L_2 \leq R_2.
  • The answer to a query is the number of pairs (i, j) such that:
    • L_1 \leq i \leq R_1 and L_2 \leq j \leq R_2
    • A_i \oplus A_j has its k-th bit set. Here \oplus denotes the bitwise XOR operation.

Note: An integer x is said to have its k-th bit set if the (unique) binary representation of x contains 2^k. For example, 5 = 101_2 = 2^0 + 2^2 has its zeroth and second bits set but not the first, while 16 = 10000_2 = 2^4 has only its fourth bit set.

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of multiple lines of input.
    • The first line of each test case contains two space-separated integers N and Q — the number of elements in array and number of queries, respectively.
    • The second line of each test case contains N space-separated integers A_1, A_2, \ldots, A_N.
    • The next Q lines describe queries. The i-th of these Q lines contains 5 space-separated integers k, L_1, R_1, L_2, R_2 — the parameters described in the statement.

Output Format

For each test case, output Q lines.The i-th of these lines should be the answer to the i-th query.

Constraints

  • 1 \leq T \leq 5 \cdot 10^4
  • 2 \leq N \leq 10^5
  • 1 \leq Q \leq 5\cdot 10^5
  • 0 \leq A_i \lt 2^{60}
  • 1 \leq L_1 \leq R_1 \lt L_2 \leq R_2 \leq N.
  • 0 \leq k \lt 60
  • The sum of N and Q over all test cases won't exceed 10^5 and 5\cdot 10^5 respectively.

Sample 1:

Input
Output
2
5 2
1 2 4 3 2
1 1 3 5 5
2 1 2 3 5
6 2
3 5 6 13 12 20
1 1 4 5 6
3 2 3 4 6
2
2
4
4

Explanation:

Test case 1: The array is A = [1, 2, 4, 3, 2].

  • Query 1: the ranges are [1, 3] and [5, 5], and k = 1. There are three pairs of (i, j)(1, 5), (2, 5), (3, 5).
    • A_1 \oplus A_5 = 1 \oplus 2 = 3 = 11_2 has its first bit set
    • A_2 \oplus A_5 = 2 \oplus 2 = 0 = 0_2 doesn't have its first bit set
    • A_3 \oplus A_5 = 4 \oplus 2 = 6 = 110_2 has its first bit set
    • So, the answer is 2.
  • Query 2: the ranges are [1, 2] and [3, 5], and now k = 2. This time, there are 6 pairs of indices. Of them, it can be verified that (1, 3) and (2, 3) are the ones that satisfy the given condition.
Next Post Previous Post
No Comment
Add Comment
comment url