当前位置:网站首页>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里.最后输出.
代码:
边栏推荐
猜你喜欢

Cloud Migration Practice of Redis

Using data intelligence, Amazon cloud technology helps companies build endogenous brand growth

重要通知 | “移动云杯”算力网络应用创新大赛初赛延期!!

系统架构系列文章三--解决传统企业核心系统的性能问题

高数_证明_曲率公式

R语言实战应用案例:论文篇(一)-特殊柱形图绘制

池化技术有多牛?来,告诉你阿里的Druid为啥如此牛逼!

什么?你还不会JVM调优?
![[Gazebo Introductory Tutorial] Lecture 3 Static/Dynamic Programming Modeling of SDF Files](/img/ec/87566763daf7faa3769ee186f93ee0.jpg)
[Gazebo Introductory Tutorial] Lecture 3 Static/Dynamic Programming Modeling of SDF Files

高数_证明_弧微分公式
随机推荐
【MinIO】工具类使用
recursive recursive function
Data product manager thing 2
Error: Rule can only have one resource source (provided resource and test + include + exclude)
Do not access Object.prototype method ‘hasOwnProperty‘ from target object....
tampercfg内核模块导致机器频繁crash
How is the monthly salary table stored in the database?Ask for a design idea
2011年下半年 系统架构设计师 下午试卷 II
一种能让大型数据聚类快2000倍的方法,真不戳
[target detection] small script: extract training set images and labels and update the index
C# WPF image is displayed without problems, but the solution does not display the image at runtime
安装mysql报错处理
【MinIO】Using tools
第五讲 测试技术与用例设计
Short read or OOM loading DB. Unrecoverable error, aborting now
缺少比较器,运放来救场!(运放当做比较器电路记录)
data product manager
awk的简单使用
学习日记8
A method that can make large data clustering 2000 times faster