Input queries

1.6

9 votes
Bit Manipulation, Basic Programming, Basics of Bit Manipulation, Greedy algorithm
Problem

You are given $$Q$$ queries. Each input query contains three integers $$l$$, $$r$$, and $$k$$. Print the maximum bitwise AND value of a subset of size $$k$$ in the segment $$[l, r]$$.

Input format

  • The first line contains an integer $$Q$$ denoting the number of queries.
  • The first line of each query contains three space-separated integers $$l$$, $$r$$, and $$k$$.

Output format

Print the maximum bitwise AND value for each query in a new line.

Constraints

\(1 \le Q \le 2e5\\ 1 \le l \le r \le 1e18\\ 1 \le k \le r-l+1\)

Sample Input
5
8 8 1
8 10 1
2 6 3
7 8 1
8 9 1
Sample Output
8
10
4
8
9
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the first query, there is only 1 possible subset {8}.

For the third query, the maximum possible AND value is only possible for subset {4,5,6}.

Editor Image

?