当前位置:网站首页>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里。最后输出。
代码:
边栏推荐
- vue 怎么清除tab 切换缓存问题 ?
- 什么?你还不会JVM调优?
- leetcode 739. Daily Temperatures 每日温度(中等)
- tensorflow安装踩坑总结
- Fragment's show and hide
- [Study Notes] Persistence of Redis
- How to code like a pro in 2022 and avoid If-Else
- Unfinished mathematics test paper ----- test paper generator (Qt includes source code)
- 递归递推之计算组合数
- 力扣解法汇总640-求解方程
猜你喜欢
2022年五大云虚拟化趋势
Stream通过findFirst()查找满足条件的一条数据
Matrix Keyboard & Calculator Small Project Based on 51 (UcosII)
[Gazebo Introductory Tutorial] Lecture 3 Static/Dynamic Programming Modeling of SDF Files
网络安全——XSS之被我们忽视的Cookie
【学习笔记】Redis的持久化
关于已拦截跨源请求CORS 头缺少 ‘Access-Control-Allow-Origin‘问题解决
MySQL - 数据库的存储引擎
【JS高级】ES5标准规范之创建子对象以及替换this_10
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
随机推荐
简单的写一个防抖跟节流
雨水中存在的PFAS化学物质对饮用水安全构成了威胁
高数_证明_弧微分公式
【剑指offer】---数组中的重复数字
2011年下半年 系统架构设计师 下午试卷 II
Fragment's show and hide
How to code like a pro in 2022 and avoid If-Else
[Study Notes] Persistence of Redis
YTU 2295: KMP pattern match one (string)
C# InitializeComponent() does not exist in the current context
面试面到了一个腾讯30k出来的,有见识到何为精通MySQL调优
CodeForces - 811A
微信扫码登陆(1)—扫码登录流程讲解、获取授权登陆二维码
Alibaba的秒杀系统—千亿级并发设计手册上线了
静态变量存储在哪个区
Interface Automation Testing Basics
Fragment的show和hide
安装mysql报错处理
C#实现访问OPC UA服务器
Fragment-hide and show