A special sequence
Practice
2.5 (29 votes)
C++
Basic programming
Bit manipulation
Basics of bit manipulation
Algorithms
Binary search
Problem
58% Success 5577 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
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
81 votes
Tags:
AlgorithmsBinary SearchEasyHash MapsSearchingSortingString Manipulation
Points:30
58 votes
Tags:
AlgorithmsEasyMonthly-ContestReady
3.Danny !
Points:30
20 votes
Tags:
Binary SearchEasySearching
Editorial
Login to unlock the editorial