我有一个关于已经问过这个问题的问题: SPOJ DQUERY : TLE Even With BIT?
如果我在进行范围查询时不想考虑重复的元素,该怎么办? 以下是一个例子:
Input
Line 1: n (1 ≤ n ≤ 10^6).
Line 2: n numbers a1, a2, ..., an (-10^9 ≤ ai ≤ ).
Line 3: q (1 ≤ q ≤ 10^6), the number of d-queries.
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.
Example
Input
9
1 2 3 2 4 1 2 3 4
3
1 9
2 4
5 9
2 7
Output
0 //Explanation: all elements have been repeated.
1 //Explanation: only 3 has not repeated.
3 //Explanation: only 4 is repeated, so count only 1, 2 and 3.
3 //Explanation: only 2 is repeated, so count only 3, 4 and 1.
在@kraskevich的答案中应该做的必要改变是什么(对于那个特定情况,这是一个有效的解决方案)?我在BIT中尝试add 0
,而不是上述解决方案中的-1
,这对所有类型的查询都没有帮助。任何人都可以给我一个想法吗?
答案 0 :(得分:0)
我终于使用MOs算法制作了它。以下将按预期工作。
ffmpeg -y -i input -c:v libx264 -crf 20 -minrate 1M -maxrate 2M -bufsize 2M output.mkv