链接:https://www.nowcoder.com/acm/contest/139/J
Given a sequence of integers a1, a2, ..., an and q pairs of integers (l1, r1), (l2, r2), ..., (lq, rq), find count(l1, r1), count(l2, r2), ..., count(lq, rq) where count(i, j) is the number of different integers among a1, a2, ..., ai, aj, aj + 1, ..., an.
The input consists of several test cases and is terminated by end-of-file. The first line of each test cases contains two integers n and q. The second line contains n integers a1, a2, ..., an. The i-th of the following q lines contains two integers li and ri.
For each test case, print q integers which denote the result.
示例1
复制
3 2 1 2 1 1 2 1 3 4 1 1 2 3 4 1 3
复制
2 1 3
* 1 ≤ n, q ≤ 105 * 1 ≤ ai ≤ n * 1 ≤ li, ri ≤ n * The number of test cases does not exceed 10.
题意:
数组从L往左,从R往右组成一个新的数组,在数组中有几个不一样的数
分析:
树状数组离线处理进行更新删除
代码:
#include
#include
#include
#include
#include