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调用Python脚本工具类
[本文出自天外归云的博客园] 在网上查了很多方法都不成功,在google上搜到一篇文章,做了一些小修改,能够处理中文输出.提取一个运行python脚本的Java工具类如下: package com.a ...
- [转]自定义注释@interface的用法
一.什么是注释 说起注释,得先提一提什么是元数据(metadata).所谓元数据就是数据的数据.也就是说,元数据是描述数据的.就象数据表中的字段一样,每个字段描述了这个字段下的数据的含义.而J ...
- C#学习笔记(13)——传统方法读取XML
说明(2017-7-12 16:32:47): 1. LINQ的方法虽然很简单,但是有点不好理解,sql的写法总感觉很诡异,而且LINQ的本质也是用的传统方法,所以还是采用老办法吧! 2. 注释里的代 ...
- .net将枚举转成List
using System; using System.Collections.Generic; using System.ComponentModel; namespace zifar.SgmhWeb ...
- Linux下用文件IO的方式操作GPIO(/sys/class/gpio)
通过sysfs方式控制GPIO,先访问/sys/class/gpio目录,向export文件写入GPIO编号,使得该GPIO的操作接口从内核空间暴露到用户空间,GPIO的操作接口包括direction ...
- SecureCRT ,可是进入模拟器后TAB键还是无法补全
SecureCRT是做网络,路由,交换机等设备的人都知道的工具 ,可是进入模拟器后TAB键还是无法补全,就很懊恼了. 设置步骤: 1)打开SecureCRT软件,选项—全局选项—常规—默认的会话设置— ...
- String Format for Double [C#]
转载:http://www.csharp-examples.net/string-format-double/ he following examples show how to format flo ...
- 15.01.29-MVC中用Areas分解项目
在MVC项目上右键->新建->区域(Areas)...,将会自动生成Areas文件夹,并在文件夹下创建Model+Controller+View的mvc框架.在Views文件夹中,自动生成 ...
- python多线程生产消费
#!/usr/bin/env python# -*- coding: utf-8 -*- from threading import Threadfrom Queue import Queueimpo ...
- php 超时 解决办法 (Maximum execution time of 30 seconds exceeded)这个问题?
1. 修改是APACHE设置,在PHP.INI中找到一个参数: max_execution_time 将后面的值调大,然后重新启动APACHE服务(centos: service httpd rest ...