当前位置:网站首页>1004 (tree array + offline operation + discretization)
1004 (tree array + offline operation + discretization)
2022-08-10 14:23:00 【51CTO】
Problem Description
After inventing Turing Tree, 3xian always felt boring when solving problems about intervals, because Turing Tree could easily have the solution. As well, wily 3xian made lots of new problems about intervals. So, today, this sick thing happens again...
Now given a sequence of N numbers A1, A2, ..., AN and a number of Queries(i, j) (1≤i≤j≤N). For each Query(i, j), you are to caculate the sum of distinct values in the subsequence Ai, Ai+1, ..., Aj.
Input
The first line is an integer T (1 ≤ T ≤ 10), indecating the number of testcases below. For each case, the input format will be like this: * Line 1: N (1 ≤ N ≤ 30,000). * Line 2: N integers A1, A2, ..., AN (0 ≤ Ai ≤ 1,000,000,000). * Line 3: Q (1 ≤ Q ≤ 100,000), the number of Queries. * Next Q lines: each line contains 2 integers i, j representing a Query (1 ≤ i ≤ j ≤ N).
Output
For each Query, print the sum of distinct values of the specified subsequence in one line.
Sample Input
Sample Output
Topics and ideas:
Find the sum of disjoint numbers.Use offline operation.
The first is to discretize.Also save the range,按照右端点排序.进行预处理.
Then loop from the first number,Put the numbers into a tree-like array,if it exists in the array,就再减去.Each to a right endpoint,Put and saveans里.最后输出.
代码:
边栏推荐
- How to code like a pro in 2022 and avoid If-Else
- C# InitializeComponent() does not exist in the current context
- A method that can make large data clustering 2000 times faster
- 【Gazebo入门教程】第三讲 SDF文件的静/动态编程建模
- YTU 2295: KMP pattern match one (string)
- 进程和计划任务管理
- [target detection] small script: extract training set images and labels and update the index
- 《论文阅读》PLATO: Pre-trained Dialogue Generation Model with Discrete Latent Variable
- Cloud Migration Practice of Redis
- 开源SPL消灭数以万计的数据库中间表
猜你喜欢
随机推荐
日志@Slf4j介绍使用及配置等级
CodeForces - 811A
A method that can make large data clustering 2000 times faster
作业
这一次,话筒给你:向自由软件之父斯托曼 提问啦!
file system design
WebView的优化与常见问题解决方案
简单的写一个防抖跟节流
FPN详解
Circle 创始人回应美财政部禁止 Tornado :隐私与安全之间关系紧张
黑客入门,从HTB开始
Fragment-hide and show
[target detection] small script: extract training set images and labels and update the index
data product manager
高数_证明_曲率公式
使用mysq语句操作数据库
《论文阅读》PLATO: Pre-trained Dialogue Generation Model with Discrete Latent Variable
CodeForces-834C
系统的安全和应用(不会点安全的东西你怎么睡得着?)
缺少比较器,运放来救场!(运放当做比较器电路记录)