oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

dquery Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

dquery.html

Given a sequence of N numbers a1, a2, ..., aN, and a number of d-queries. A d-query is a pair (i, j) (1 ≤ i ≤ j ≤ N). For each d-query (i, j), you have to return the number of distinct elements in the subsequence ai, ai + 1, ..., aj.

Input

  • Line 1: N (1 ≤ N ≤ 200000).
  • Line 2: N numbers a1, a2, ..., aN (1 ≤ ai ≤ 106).
  • Line 3: Q (1 ≤ Q ≤ 200000).
  • In the next Q lines, each line contains 2 numbers, i, j representing a d-query (1 ≤ i ≤ j ≤ N).

Output

  • For each d-query (i, j), print the number of distinct elements in the subsequence ai, ai + 1, ..., aj in a single line.

Sample Input 1

5
1 1 2 1 3
3
1 5
2 4
3 5

Sample Output 1

3
2
3

Sample Input 2

10
8 1 4 3 10 1 7 4 8 1
5
1 1
3 4
2 9
2 2
4 10

Sample Output 2

1
2
6
1
6

Tags

SPOJ

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
1100201s256MBMinimum
2021s256MBMinimum

Judge Compile Command

g++-8 ans.cpp -o dquery -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.