HDU5086Revenge of Segment Tree(数论)

pid=5086" target="_blank" style="">题目链接

题目大意:给出长度为n的数组。然后要求累计里面的每一个子串的和。

解题思路:枚举起点和终点,推断每一个数属于多少条线段。那么这个数就要被加这么多次。能够得出每一个位置被加次数的公式: i
(n - i + 1);那么结果就是累计(arr[i] i) mod * (n - i + 1) % mod,注意两个数相乘可能会超出long long型的数。

代码:

#include <cstdio>
#include <cstring> typedef long long ll; const int maxn = 1e6;
const ll mod = 1e9 + 7; ll arr[maxn]; int main () { int T, n;
scanf ("%d", &T);
while (T--) { scanf ("%d", &n);
for (int i = 1; i <= n; i++)
scanf ("%I64d", &arr[i]); ll ans = 0;
for (int i = 1; i <= n; i++)
ans = (ans + (arr[i] * i % mod) * (n - i + 1) % mod) % mod;
printf ("%I64d\n", ans);
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

HDU5086Revenge of Segment Tree(数论)的更多相关文章

  1. HDU-5086-Revenge of Segment Tree

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5086 这题太不应该了,比赛时没做出来,本来呢,以现在的水平这题是能够做出来的,可就是题目理解错了,按题 ...

  2. BestCoder#16 A-Revenge of Segment Tree

    Revenge of Segment Tree Problem Description In computer science, a segment tree is a tree data struc ...

  3. [LintCode] Segment Tree Build II 建立线段树之二

    The structure of Segment Tree is a binary tree which each node has two attributes startand end denot ...

  4. [LintCode] Segment Tree Build 建立线段树

    The structure of Segment Tree is a binary tree which each node has two attributes start and end deno ...

  5. Segment Tree Modify

    For a Maximum Segment Tree, which each node has an extra value max to store the maximum value in thi ...

  6. Segment Tree Query I & II

    Segment Tree Query I For an integer array (index from 0 to n-1, where n is the size of this array), ...

  7. Segment Tree Build I & II

    Segment Tree Build I The structure of Segment Tree is a binary tree which each node has two attribut ...

  8. Lintcode: Segment Tree Query II

    For an array, we can build a SegmentTree for it, each node stores an extra attribute count to denote ...

  9. Lintcode: Segment Tree Modify

    For a Maximum Segment Tree, which each node has an extra value max to store the maximum value in thi ...

随机推荐

  1. NFS服务器端配置

    服务器端配置1 创建共享目录# mkdir /home/share# chown nobody.nogroup /home/share2 创建或修改/etc/exports 配置文件这个文件的内容非常 ...

  2. fake it till you become it

    fake it till you become it_你泛起山川烟波里的不是我._百度空间 fake it till you become it

  3. HDU--杭电--4504--威威猫系列故事——篮球梦--DP

    威威猫系列故事——篮球梦 Time Limit: 300/100 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total ...

  4. JVM查找类文件的顺序(转)

    配置classpath 根据path环境变量的原理,可以定义一个名为classpath环境变量,将要运行的class文件所在目录定义在该变量中. 例:set classpath=c:\ classpa ...

  5. C++著名类库和C++标准库介绍

    C++著名类库 1.C++各大有名库的介绍——C++标准库 2.C++各大有名库的介绍——准标准库Boost 3.C++各大有名库的介绍——GUI 4.C++各大有名库的介绍——网络通信 5.C++各 ...

  6. Functional Jobs // Hire Functional Programmers In Less Time

    Functional Jobs // Hire Functional Programmers In Less Time Hire Functional Programmers Quick Save T ...

  7. 超人学院Hadoop大数据技术资源分享

    超人学院Hadoop大数据技术资源分享 http://bbs.superwu.cn/forum.php?mod=viewthread&tid=807&fromuid=645 很多其它精 ...

  8. Powershell Mail module, 发送outbox 里的全部邮件(一个.csv文件代表一封邮件)

    把creating mail代码写到调用处,往outbox写入 mailxxx.csv文件,入面记录了邮件的主要内容 写入 #template $TMP = IMPORT-CSV "$($d ...

  9. margin 等高布局

    <div id="main"> <div id="left"> 我是左边的内容的啦啦啦啦... .<br> 我是左边的内容的 ...

  10. POJ题目分类【实在是不知道哪个是原创了】

    原地址:http://blog.csdn.net/liuqiyao_01/article/details/8477801 初期:一.基本算法:     (1)枚举. (poj1753,poj2965) ...