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 题目大意:给你一个树 判断这棵树是否是独特的 一颗树是独特的条件:不存在一颗和它本身不同但相似的树 两颗树 ...
随机推荐
- 有了#ifdef 为什么还需要#if defined
有了#ifdef 为什么还需要#if defined ? #include <stdio.h> #define A #define B void test(int a,int b) { ...
- 使用一层神经网络训练mnist数据集
import numpy as np import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_dat ...
- Linux 增量系统备份和部分还原策略
. . . . . 完全用 Linux 已经有快半年的时间了,一直想要全盘备份一下数据,但是却一直没有做,为什么呢? 一方面是东西比较多,备份一次要很长的时间:另一方面是一直在纠结用哪种方式备份比较好 ...
- android App抓包工具的应用(转)
安装好 fiddler ,手头有一部Android 手机,同时 还要有无线网,手机和 电脑在同一个无线网络.这些条件具备,我们就可以 开始下面的步骤了. 正题 :Fiddler 主菜单 Tools - ...
- WPF DataTomplate中Command无效
问题:在DataTomplate中添加一个Button,Button添加Command,但是Command生效. 原因:ItemTemplate的DataContext指代不明,需要改为父类的Data ...
- log_bin_trust_function_creators
log_bin_trust_function_creators错误解决 当有mysql本地或远程建立function或procedure时报上面的错误 或者如果开启了二进制日志,但是用户没有suppe ...
- [算法]从一道题引出variable-precision SWAR算法
苏君君出了一道题,是牛客网上面的: 输入一个int型整数,输出该数二进制表示中1的个数.其中负数用补码表示. 其实这道题并不难,大家很容易想到的解法是转成字符串的思路,即如下所示: public st ...
- hbase源码系列(十二)Get、Scan在服务端是如何处理?
继上一篇讲了Put和Delete之后,这一篇我们讲Get和Scan, 因为我发现这两个操作几乎是一样的过程,就像之前的Put和Delete一样,上一篇我本来只打算写Put的,结果发现Delete也可以 ...
- eclipse中设置字体为VC经典字体Fixedsys
- 通过URI返回File文件
/** * 通过Uri返回File文件 * 注意:通过相机的是类似content://media/external/images/media/97596 * 通过相册选择的:file:///stora ...