hdu 5086 Revenge of Segment Tree(BestCoder Round #16)
Revenge of Segment Tree
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 420 Accepted Submission(s): 180
structure is built. A similar data structure is the interval tree.
A segment tree for a set I of n intervals uses O(n log n) storage and can be built in O(n log n) time. Segment trees support searching for all the intervals that contain a query point in O(log n + k), k being the number of retrieved intervals or segments.
---Wikipedia
Today, Segment Tree takes revenge on you. As Segment Tree can answer the sum query of a interval sequence easily, your task is calculating the sum of the sum of all continuous sub-sequences of a given number sequence.
Each test case begins with an integer N, indicating the length of the sequence. Then N integer Ai follows, indicating the sequence.
[Technical Specification]
1. 1 <= T <= 10
2. 1 <= N <= 447 000
3. 0 <= Ai <= 1 000 000 000
2
1
2
3
1 2 3
2
20HintFor the second test case, all continuous sub-sequences are [1], [2], [3], [1, 2], [2, 3] and [1, 2, 3]. So the sum of the sum of the sub-sequences is 1 + 2 + 3 + 3 + 5 + 6 = 20.
Huge input, faster I/O method is recommended. And as N is rather big, too straightforward algorithm (for example, O(N^2)) will lead Time Limit Exceeded.
And one more little helpful hint, be careful about the overflow of int.
考虑每一个数出如今多少个子序列之中。如果第i个数为Ai。区间为[L,R]。 那么包括Ai的区间满足L⩽i⋂R⩾i。累加(L+1)∗(N−R)∗A[i]就能够了。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
long long mod=1000000000+7;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
long long n;
long long ans=0;
long long a;
scanf("%I64d",&n);
for(int i=0;i<n;i++)
{
scanf("%I64d",&a);
ans=(ans+(((a*(i+1)%mod)*(n-i))%mod))%mod;
}
printf("%I64d\n",ans);
}
return 0;
}
hdu 5086 Revenge of Segment Tree(BestCoder Round #16)的更多相关文章
- HDU5086——Revenge of Segment Tree(BestCoder Round #16)
Revenge of Segment Tree Problem DescriptionIn computer science, a segment tree is a tree data struct ...
- [ACM] HDU 5086 Revenge of Segment Tree(全部连续区间的和)
Revenge of Segment Tree Problem Description In computer science, a segment tree is a tree data struc ...
- HUD 5086 Revenge of Segment Tree(递推)
http://acm.hdu.edu.cn/showproblem.php?pid=5086 题目大意: 给定一个序列,求这个序列的子序列的和,再求所有子序列总和,这些子序列是连续的.去题目给的第二组 ...
- HDU5087——Revenge of LIS II(BestCoder Round #16)
Revenge of LIS II Problem DescriptionIn computer science, the longest increasing subsequence problem ...
- hdu5086——Revenge of Segment Tree
Revenge of Segment Tree Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- BestCoder Round #16
BestCoder Round #16 题目链接 这场挫掉了,3挂2,都是非常sb的错误 23333 QAQ A:每一个数字.左边个数乘上右边个数,就是能够组成的区间个数,然后乘的过程注意取模不然会爆 ...
- hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]
传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131 ...
- HDU 5228 ZCC loves straight flush( BestCoder Round #41)
题目链接:pid=5228">ZCC loves straight flush pid=5228">题面: pid=5228"> ZCC loves s ...
- HDU 5432 Rikka with Tree (BestCoder Round #53 (div.2))
http://acm.hdu.edu.cn/showproblem.php?pid=5423 题目大意:给你一个树 判断这棵树是否是独特的 一颗树是独特的条件:不存在一颗和它本身不同但相似的树 两颗树 ...
随机推荐
- java 泛型详解-绝对是对泛型方法讲解
Reference: http://blog.csdn.net/s10461/article/details/53941091 1. 概述 泛型在java中有很重要的地位,在面向对象编程及各种设计模 ...
- 针对后台TCP服务F5健康检查配置
1.TCP-HALF-OPEN方式 TCP-HALF-OPEN的探测方式,实际是F5每隔一个固定的时间,发送一个SYN包给资源池pool中的一个member,等待服务器返回SYN_ACK,在收到SYN ...
- redis集群主流架构方案分析
Redis在互联网大数据平台有着广泛的应用,主要被用来缓存热点数据,避免海量请求压垮数据库,同时可以提升服务节点的响应速度和并发量.随着数据量的增多,由于redis是占用单台物理机或虚机的内存,内存资 ...
- org.apache.hadoop.hbase.MasterNotRunningException解决策略
执行HBase时常会遇到个错误,我就有这种经历. ERROR: org.apache.hadoop.hbase.MasterNotRunningException: Retried 7 times 检 ...
- 【Unity笔记】寻路导航用NavMeshObstacle做动态阻挡
通常情况下,静态的场景中,给场景物体静态标记中勾选Navigation Static后,在导航界面进行导航网格的烘培,可以得到一个静态的导航网格. 但是由于导航网格是静态烘焙好了的,游戏中动态生成的物 ...
- InstallShield卸载状态
uninstallaing() 它对应于-unistall 命令,在installshield 2009及之前的版本,在控制面板中选择"uninstall”会触发这个命令.但在install ...
- C# DIctionary:集合已修改,可能无法执行枚举操作
C#中直接对集合Dictionary进行遍历并修改其中的值,会报错,如下代码就会报错:集合已修改;可能无法执行枚举操作.代码如下 public void ForeachDic() { Dictiona ...
- 看不懂深度Linux系统的文件管理器图标
为了保持对Linux的熟悉度,MacBookPro一般放在公司,家里(每次用这个词是我觉得最纠结的时候,我现在有家吗?)用的是普通笔记本装了深度Linux. 之所以安装深度,主要的原因应该是支持国产吧 ...
- Android——修改Button样式,动态修改Button中的图片大小
原文地址: http://www.cnblogs.com/gzggyy/archive/2013/05/17/3083218.html http://www.xuebuyuan.com/2173740 ...
- jmx学习
原文地址:https://www.cnblogs.com/dongguacai/p/5900507.html 一.JMX的定义 JMX(Java Management Extensions)是一个为应 ...