DQUERY  Dquery
English  Vietnamese 
Given a sequence of n numbers a_{1}, a_{2}, ..., a_{n} and a number of dqueries. A dquery is a pair (i, j) (1 ≤ i ≤ j ≤ n). For each dquery (i, j), you have to return the number of distinct elements in the subsequence a_{i}, a_{i+1}, ..., a_{j}.
Input
 Line 1: n (1 ≤ n ≤ 30000).
 Line 2: n numbers a_{1}, a_{2}, ..., a_{n} (1 ≤ a_{i} ≤ 10^{6}).
 Line 3: q (1 ≤ q ≤ 200000), the number of dqueries.
 In the next q lines, each line contains 2 numbers i, j representing a dquery (1 ≤ i ≤ j ≤ n).
Output
 For each dquery (i, j), print the number of distinct elements in the subsequence a_{i}, a_{i+1}, ..., a_{j} in a single line.
Example
Input 5 1 1 2 1 3 3 1 5 2 4 3 5 Output 3 2 3
hide comments
akshatjain02:
20180414 23:22:18
Solved it using both Mo's Algorithm and Offline Segment Tree :') 

ac_traits:
20180411 10:58:55
I set maxN = (int)3e4 + 10 and get AC 

gangchil:
20180329 12:08:47
mo with cin/cout gives tle use printf/scanf instead (.31s)and value of n is probably <= 300010 costed me lots of wa ;) Last edit: 20180331 01:29:59 

da_201501443:
20180306 14:20:28
Can anybody share your code ??


da_201501443:
20180306 14:00:32
@mmshn1380


mmshn1380:
20180303 18:06:44
why my code get TLE :/


humiko_1:
20180221 20:19:12
n is smaller or equal to 3*10^5, not 3*10^4. Please fix that. 

Kishore:
20180213 07:45:41
did anyone do it in java? I did it using MO along with fast I/o but getting TLE 

jatin_tayal:
20180114 18:46:46
don't use pair while using MO , use a structure instead !


karthik1997:
20171229 12:37:02
Cant Believe it . With Fast I/O ,my results are :

Added by:  Duc 
Date:  20081026 
Time limit:  1s1.5s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ERL JSRHINO NODEJS PERL6 VB.NET 
Resource:  © VNOI 