-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsave mrinal
More file actions
47 lines (39 loc) · 1.36 KB
/
save mrinal
File metadata and controls
47 lines (39 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
Mrinal is a coder from BVCOE. He always takes his laptop with him wherever he goes. One day (while on a trek trip ) a monster challenged him
to solve one easy task else he was going to kill him.the task is as follows- Given a series of n numbers a1, a2, ..., an and a number of magic-
queries. A magic-query is a pair (i, j) (1 ≤ i ≤ j ≤ n). For each magic-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 ≤ 30000). Line 2: n numbers a1, a2, ..., an (1 ≤ ai ≤ 10^6). Line 3: q (1 ≤ q ≤ 200000), the number of magic-queries. In the
next q lines, each line contains 2 numbers i, j representing a magic-query (1 ≤ i ≤ j ≤ n).
Output
For each magic-query (i, j), print the number of distinct elements in the subsequence ai, ai+1, ..., aj in a single line. Example
SAMPLE INPUT
5
1 1 2 1 3
3
1 5
2 4
3 5
SAMPLE OUTPUT
3
2
3
Explanation
In the first Case, there are three distinct Elemenst ie 1,2 and 3
*/
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,q,l,r; cin>>n;
int a[n]; for(int i=0; i<n; i++) cin>>a[i];
cin>>q;
while(q--){
cin>>l>>r;
unordered_map<int,int> m;
for(int i=l-1; i<r; i++){
m[a[i]]++;
}
cout<<m.size()<<'\n';
}
}