HDU - 3874 Necklace (线段树 + 离线处理)
NecklaceTime Limit: 15000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Problem Description
Mery has a beautiful necklace. The necklace is made up of N magic balls. Each ball has a beautiful value. The balls with the same beautiful value look the same, so if two or more balls have the same beautiful value, we just count it once. We define the beautiful
value of some interval [x,y] as F(x,y). F(x,y) is calculated as the sum of the beautiful value from the xth ball to the yth ball and the same value is ONLY COUNTED ONCE. For example, if the necklace is 1 1 1 2 3 1, we have F(1,3)=1, F(2,4)=3, F(2,6)=6. Now Mery thinks the necklace is too long. She plans to take some continuous part of the necklace to build a new one. She wants to know each of the beautiful value of M continuous parts of the necklace. She will give you M intervals [L,R] (1<=L<=R<=N) and you must tell her F(L,R) of them.
Input
The first line is T(T<=10), representing the number of test cases.
For each case, the first line is a number N,1 <=N <=50000, indicating the number of the magic balls. The second line contains N non-negative integer numbers not greater 1000000, representing the beautiful value of the N balls. The third line has a number M, 1 <=M <=200000, meaning the nunber of the queries. Each of the next M lines contains L and R, the query.
Output
For each query, output a line contains an integer number, representing the result of the query.
Sample Input
Sample Output
|
HDU - 3874 Necklace (线段树 + 离线处理)的更多相关文章
- Necklace HDU - 3874 (线段树/树状数组 + 离线处理)
Necklace HDU - 3874 Mery has a beautiful necklace. The necklace is made up of N magic balls. Each b ...
- HDU 3874 Necklace (树状数组 | 线段树 的离线处理)
Necklace Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- HDU 4638-Group(线段树+离线处理)
题意: 给n个编号,m个查询每个查询l,r,求下标区间[l,r]中能分成标号连续的组数(一组内的标号是连续的) 分析: 我们认为初始,每个标号为一个组(线段树维护区间组数),从左向右扫序列,当前标号, ...
- HDU 4417 【线段树+离线处理】
http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意:找出给定区间内,有多少个数小于等于给定的数.用线段树维护的话会超时,要用到线段树的离线操作,对询问与 ...
- hdu 4288 Coder (线段树+离线)
题意: 刚开始有一个空集合.有三种操作: 1.往集合中加入一个集合中不存在的数 x 2.从集合中删除一个已经存在的数 x 3.计算集合的digest sum并输出. digest sum求 ...
- HDU-3874 Necklace 线段树+离线
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3874 比较简单的题,题意也好懂. 先O(n)求每个数左边第一次出现的与他相同的数的位置l[i].对询问 ...
- hdu 3874 Necklace(bit树+事先对查询区间右端点排序)
Mery has a beautiful necklace. The necklace is made up of N magic balls. Each ball has a beautiful v ...
- HDU 3874 离线段树
在所有数字的统计范围,,对于重复统计只有一次 离线段树算法 排序终点坐标.然后再扫,反复交锋.把之前插入树行被删除 #include "stdio.h" #include &quo ...
- HDU3874 线段树 + 离线处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3874 , 线段树(或树状数组) + 离线处理 下午做了第一道离线处理的题目(HDU4417),多少有点 ...
随机推荐
- git下载其他人分支的代码
1. 在工作空间,右键,打开Git Bash 2. clone主分支的代码(即下载主分支代码的过程) 执行命令: git clone xxx.git 3. 进入工程目录 cd xxx 4. 切换到 ...
- vue父组件向子组件传递数据
父组件 <template> <div id="app"> <v-header :childseller="fatherseller&quo ...
- 【CF1068B】LCM(数学)
题意:给定b,求lcm(a,b)/a有几种不同的取值 b<=1e10 思路:只有a取b的因子时答案两两不同 #include<cstdio> #include<cstring& ...
- [LeetCode] Sum Root to Leaf Numbers dfs,深度搜索
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...
- macro expand error
cat test_macro.c #define TEST_MACRO(b) chip->##b int main(void) { TEST_MACRO(yyy) return 0; } gcc ...
- Scrapy笔记:使用scrapy shell url时出现403错误的解决办法
参考 : http://www.th7.cn/Program/Python/201704/1154208.shtml 原因是网站的防爬虫配置起到了作用 (1):第一种方法是在命令上加上-s USER_ ...
- hdu 3579(中国剩余定理+考虑0)
Hello Kiki Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- bytearray和file的后端上传方式
public static String readAndUpload(String serverpath,String imgid) { if(serverpath==null){ serverpat ...
- 牛客网 牛客小白月赛1 F.三视图
F.三视图 链接:https://www.nowcoder.com/acm/contest/85/F来源:牛客网 这个题自己想一下三维的,正视图和左视图中y轴为行数,x轴和z轴是列数,因为 ...
- ORACLE SQL*PLUS环境变量设置及说明
1:查看当前用户的环境设置: SQL> define DEFINE _DATE " (CHAR) DEFINE _CONNECT_IDENTIFIER = "updb&quo ...