当前位置:网站首页>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里.最后输出.
代码:
边栏推荐
- Summary of tensorflow installation stepping on the pit
- 系统架构系列文章三--解决传统企业核心系统的性能问题
- Stream通过findFirst()查找满足条件的一条数据
- 重要通知 | “移动云杯”算力网络应用创新大赛初赛延期!!
- Matrix Keyboard & Calculator Small Project Based on 51 (UcosII)
- 一种能让大型数据聚类快2000倍的方法,真不戳
- Short read or OOM loading DB. Unrecoverable error, aborting now
- Borg Maze (bfs+最小生成树)
- Using data intelligence, Amazon cloud technology helps companies build endogenous brand growth
- 2022年中国软饮料市场洞察
猜你喜欢
MySQL - storage engine for databases
什么?你还不会JVM调优?
借数据智能,亚马逊云科技助力企业打造品牌内生增长力
普林斯顿微积分读本05第四章--求解多项式的极限问题
Do not access Object.prototype method ‘hasOwnProperty‘ from target object....
How does IT Xiaobai learn PHP systematically
ABAP file operations involved in the Chinese character set of problems and solutions for trying to read
关于已拦截跨源请求CORS 头缺少 ‘Access-Control-Allow-Origin‘问题解决
1W字详解线程本地存储 ThreadLocal
系统架构系列文章三--解决传统企业核心系统的性能问题
随机推荐
Error: Rule can only have one resource source (provided resource and test + include + exclude)
MySQL interview questions
How to code like a pro in 2022 and avoid If-Else
安装mysql报错处理
微信扫码登陆(1)—扫码登录流程讲解、获取授权登陆二维码
FPN详解
Lack of comparators, op amps come to the rescue!(Op amp is recorded as a comparator circuit)
注意力模型---Attention Model
epoll学习:思考一种高性能的服务器处理框架
file system design
IT小白怎么系统的php学习
作业8.9 构建TCP协议的服务器
Drive IT Modernization with Low Code
【JS高级】ES5标准规范之创建子对象以及替换this_10
锂电池技术
【有限元分析】异型密封圈计算泄漏量与参数化优化过程(带分析源文件)
mysql进阶(三十三)MySQL数据表添加字段
Unfinished mathematics test paper ----- test paper generator (Qt includes source code)
统信 UOS V20 专业版(1050update2)发布:文件共享、全局搜索等优化
“Oracle 封禁了我的账户”