A special sequence
Practice
2.5 (29 votes)
C++
Basic programming
Bit manipulation
Basics of bit manipulation
Algorithms
Binary search
Problem
58% Success 5576 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

An array \(A\) contains integers with the following constraints:

  • \(A\) contains elements in sorted order.
  • Integer \(i\) occurs \(i \times floor(sqrt(i)) + ceil(i/2)\) times in the array. 
  • All elements are greater than or equal to \(1\).

You are given \(Q\) queries of type:

  • \(L \ R\): Find the number of distinct values present in subarray \(A[L...R]\)

Note: 1-based indexing is followed.

Input format

  • The first line contains an integer \(Q\) denoting the number of queries.
  • Next \(Q\) lines contains two space-separated integers \(L \ R\), denoting the query.

Output format

For each query in a new line, print the required number of distinct values.

Constraints

\(1 \le Q \le 10^5 \\ 1 \le L \le R \le 10^{13}\)

 

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
3 votes
Tags:
Binary SearchEasySearching
Points:30
11 votes
Tags:
AlgorithmsBinary SearchEasySearching
Points:30
58 votes
Tags:
AlgorithmsEasyMonthly-ContestReady