Range Queries
Practice
4.5 (2 votes)
Bit manipulation
Basics of bit manipulation
Basic programming
Problem
24% Success 1700 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Given \(Q\) queries of type \(L \ R \ X\), find the count of integers in range \([L, R]\) such that their \(X^{th}\) bit (1-indexed) is \(ON\) from the LSB (least significant bit) side.
Input Format:
- First line contains an integer \(Q\), denoting the number of queries.
- Next \(Q\) lines contains three space-separated integres \(L \ R \ X\).
Output Format:
For every query, print the number of integers in \([L, R]\) which satisfy the above condition.
Constraints:
\(1 \le Q \le 10^5\)
\(1 \le L \le R \le 10^5\)
\(1 \leq X \leq 20\)
Explanation
- Binary representation of integers in range \([2,6]\) are as follows:-
- 2 : 10
- 3 : 11
- 4 : 100
- 5 : 101
- 6 : 110
- There are three integers with X-th bit ON i.e. 2, 3 and 6.
- Thus, required answer is 3.
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
12 votes
Tags:
Bit ManipulationBasic ProgrammingBasics of Bit Manipulation
Points:20
10 votes
Tags:
ApprovedBasic ProgrammingBit manipulationEasyGrammar-VerifiedImplementationPriority queueReadyRecruit
Points:20
96 votes
Tags:
Basic ProgrammingBit Manipulation
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output