当前位置:网站首页>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里.最后输出.
代码:
边栏推荐
- 【ECCV 2022|Millions of Prizes】PSG Competition: Pursuing the "Most Comprehensive" Scene Understanding
- 文件系统设计
- 力扣解法汇总640-求解方程
- 安装mysql报错处理
- 高薪程序员&面试题精讲系列135之你对分布式是怎么理解的?CAP理论你知道吗?
- 2011年下半年 系统架构设计师 下午试卷 II
- Do not access Object.prototype method ‘hasOwnProperty‘ from target object....
- [219] The training course notes of the go engineer with more than 3,000 MOOCs 02 Programming ideas in the go language
- MySQL - 数据库的存储引擎
- NAACL 2022 | 简单且高效!随机中间层映射指导的知识蒸馏方法
猜你喜欢

面试面到了一个腾讯30k出来的,有见识到何为精通MySQL调优

高数_证明_弧微分公式

Error: Rule can only have one resource source (provided resource and test + include + exclude)

A unit test report for CRM One Order Application log

进程和计划任务管理

1W word detailed thread local storage ThreadLocal

Error: Rule can only have one resource source (provided resource and test + include + exclude)

Lack of comparators, op amps come to the rescue!(Op amp is recorded as a comparator circuit)

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

开源SPL消灭数以万计的数据库中间表
随机推荐
EVE模拟器的使用-带图超详细(学网络用)「建议收藏」
发送post请求前台无法获取数据
镜像瘦身:每一层都不能放过
使用决策树对鸢尾花进行分类
作业8.9 构建TCP协议的服务器
Classifying irises using decision trees
d为何用模板参数
MySQL - storage engine for databases
黑客入门,从HTB开始
R语言实战应用案例:论文篇(一)-特殊柱形图绘制
静态变量存储在哪个区
antd组件中a-modal设置固定高度,内容滚动显示
OpenStack-related commands that need to be recorded _ self-use
Stream通过findFirst()查找满足条件的一条数据
YTU 2295: KMP pattern match one (string)
强意识 压责任 安全培训筑牢生产屏障
串口服务器调试助手使用教程,串口调试助手使用教程【操作方式】
Short read or OOM loading DB. Unrecoverable error, aborting now
R语言使用gt包和gtExtras包优雅地、漂亮地显示表格数据:gtExtras包的gt_highlight_rows函数高亮(highlight)表格中特定的数据行、配置高亮行的特定数据列数据加粗
图式图例规范尺寸