← All problemsSign in

Distinct Numbers

You are given an array with N numbers. Your aim is to find the number of distinct numbers in the index range L to R for each of the Q queries. Input N A1 A2 . . . . . . .AN Q L1 R1 L2 R2 . . . . LQ RQ Output Print the answer for each query on a newline Constraints - 1 ≤ N,Q ≤ 106 - 1 ≤ L ≤ R ≤ N - 0 ≤ Ai ≤ 109 Example 1 10 1 1 2 3 4 4 5 6 7 1 1 1 10 Answer 7 since there are seven disti

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start