当前位置:网站首页>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里。最后输出。
代码:
边栏推荐
- 汉字检测和关键词检测
- Circle 创始人回应美财政部禁止 Tornado :隐私与安全之间关系紧张
- Using data intelligence, Amazon cloud technology helps companies build endogenous brand growth
- leetcode 739. Daily Temperatures 每日温度(中等)
- 关于已拦截跨源请求CORS 头缺少 ‘Access-Control-Allow-Origin‘问题解决
- 学习日记8
- 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
- 实现一个深克隆
- 镜像瘦身:每一层都不能放过
- MQTT服务器搭建
猜你喜欢
随机推荐
关于已拦截跨源请求CORS 头缺少 ‘Access-Control-Allow-Origin‘问题解决
1W word detailed thread local storage ThreadLocal
这一次,话筒给你:向自由软件之父斯托曼 提问啦!
A unit test report for CRM One Order Application log
C# error The 'xmins' attribute is not supported in this context
简单的写一个防抖跟节流
缺少比较器,运放来救场!(运放当做比较器电路记录)
SecureCRTPortable – 破解
MySQL - 数据库的存储引擎
laravel throws the error to Dingding
Classifying irises using decision trees
【目标检测】小脚本:提取训练集图片与标签并更新索引
MQTT服务器搭建
win2012安装Oraclerac失败
EVE模拟器的使用-带图超详细(学网络用)「建议收藏」
List集合
C# WPF image is displayed without problems, but the solution does not display the image at runtime
作业8.9 构建TCP协议的服务器
镜像瘦身:每一层都不能放过
MySQL - storage engine for databases









