当前位置:网站首页>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里。最后输出。
代码:
边栏推荐
- AWS Security Fundamentals
- “Oracle 封禁了我的账户”
- 系统架构系列文章三--解决传统企业核心系统的性能问题
- Drive IT Modernization with Low Code
- 1W word detailed thread local storage ThreadLocal
- 从洞察到决策,一文解读标签画像体系建设方法论
- C# InitializeComponent() does not exist in the current context
- 关于已拦截跨源请求CORS 头缺少 ‘Access-Control-Allow-Origin‘问题解决
- 锂电池技术
- vivado闪退或者message无显示
猜你喜欢

发送post请求前台无法获取数据

AWS 安全基础知识

从洞察到决策,一文解读标签画像体系建设方法论

【Gazebo入门教程】第三讲 SDF文件的静/动态编程建模

正则表达式(包含各种括号,echo,正则三剑客以及各种正则工具)

图式图例规范尺寸

基于ArcGIS水文分析、HEC-RAS模拟技术在洪水危险性及风险评估

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

使用决策树对鸢尾花进行分类

Short read or OOM loading DB. Unrecoverable error, aborting now
随机推荐
安装mysql报错处理
作业8.9 构建TCP协议的服务器
Data product manager thing 2
实现一个深克隆
Matrix Keyboard & Calculator Small Project Based on 51 (UcosII)
Short read or OOM loading DB. Unrecoverable error, aborting now
SQL学习(基础)
Stream通过findFirst()查找满足条件的一条数据
PEST 分析法
vivado闪退或者message无显示
递归递推之递归的函数
重要通知 | “移动云杯”算力网络应用创新大赛初赛延期!!
ABAP file operations involved in the Chinese character set of problems and solutions for trying to read
普林斯顿微积分读本05第四章--求解多项式的极限问题
vue 怎么清除tab 切换缓存问题 ?
Lack of comparators, op amps come to the rescue!(Op amp is recorded as a comparator circuit)
从洞察到决策,一文解读标签画像体系建设方法论
第三方软件测评有什么作用?权威软件检测机构推荐
雨水中存在的PFAS化学物质对饮用水安全构成了威胁
Fragment-hide and show