FZU 1656 How many different numbers

 

How many different numbers
Time Limit:1sMemory limit:32M
Accepted Submit:70Total Submit:490

 

Recently oaiei has encountered a problem. And he needs your help.
There are N numbers in an array and Q queries. For each query, there are two integers S and T. And the proplem is that there are how many different numbers in the index range [S,T] of the array (the array ‘s index is started from 1).

Input

 

There are multiple test cases. For each test case, the first line is an integer N (1<=N<=100000), indicating there are N numbers in the array. In the second line,there are N integers which are separated by a space. The third line is an integer Q(1<=Q<=1000), indicating there are Q queries. The following Q lines, for each line, there are two integers S and T(1<=S<=T<=N), indicating the index range of the array. The element value of the array will fit in a signed 32-bit integer.

 

Output

 

For each test, output an integer, indicating the number of different numbers in the index range [S,T] of the array.

 

Sample Input

10
1 2 3 3 3 3 4 -9 -9 10
2
1 5
5 10

Sample output

3
4 

Original: FOJ月赛-2008年10月

 

解题:

       用一般解法将会超时。用结构体存储给定的数字和下标。然后对结构体数组进行排序,排序后回归原下标序列。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值