当前位置:网站首页>1004(树状数组+离线操作+离散化)
1004(树状数组+离线操作+离散化)
2022-08-10 14:09: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
题目大概和思路:
求不重合数的和。用离线操作。
首先要进行离散化。还要把区间存起来,按照右端点排序。进行预处理。
然后从第一个数开始循环,把数放到树状数组里,如果数组中存在了,就再减去。每到一个右端点,就把和存到ans里。最后输出。
代码:
边栏推荐
- OpenStack-related commands that need to be recorded _ self-use
- MySQL interview questions
- Short read or OOM loading DB. Unrecoverable error, aborting now
- 1W字详解线程本地存储 ThreadLocal
- 使用决策树对鸢尾花进行分类
- AWS 安全基础知识
- 作业8.9 构建TCP协议的服务器
- How does IT Xiaobai learn PHP systematically
- Calculate the number of combinations recursively
- 注意力模型---Attention Model
猜你喜欢
Cloud Migration Practice of Redis
Short read or OOM loading DB. Unrecoverable error, aborting now
【量化交易行情不够快?】一文搞定通过Win10 wsl2 +Ubuntu+redis+pickle实现股票行情极速读写
2022-08-09: What does the following go code output?A: No, it will panic; B: Yes, it can run correctly; C: Not sure, see the voting result.package main import (“fmt“ “syn
MySQL - storage engine for databases
字节终面:CPU 是如何读写内存的?
发送post请求前台无法获取数据
IT小白怎么系统的php学习
使用mysq语句操作数据库
八大排序总是忘?快来这里~
随机推荐
数据产品经理那点事儿 一
2022-08-09: What does the following go code output?A: No, it will panic; B: Yes, it can run correctly; C: Not sure, see the voting result.package main import (“fmt“ “syn
一种能让大型数据聚类快2000倍的方法,真不戳
【ECCV 2022|百万奖金】PSG大赛:追求“最全面”的场景理解
Do not access Object.prototype method ‘hasOwnProperty‘ from target object....
X5WebView使用
2022年中国软饮料市场洞察
Pointer (preliminary solution of C language)
How to describe multiple paragraphs with different font settings in Open Office XML format
重要通知 | “移动云杯”算力网络应用创新大赛初赛延期!!
Fragment的show和hide
池化技术有多牛?来,告诉你阿里的Druid为啥如此牛逼!
Alibaba的秒杀系统—千亿级并发设计手册上线了
PHP judges whether the file has content, and if there is no content, copy another file to write
SecureCRTPortable – 破解
安装mysql报错处理
文件系统设计
【219】慕课三千多的那个go工程师的培训课笔记 02 go语言的编程思想
系统架构系列文章三--解决传统企业核心系统的性能问题
一汽奥迪:持续34年聚焦品质与体验 立足市场需求推进产品迭代