HDU5086Revenge of Segment Tree(数论)
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(数论)的更多相关文章
- HDU-5086-Revenge of Segment Tree
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5086 这题太不应该了,比赛时没做出来,本来呢,以现在的水平这题是能够做出来的,可就是题目理解错了,按题 ...
- BestCoder#16 A-Revenge of Segment Tree
Revenge of Segment Tree Problem Description In computer science, a segment tree is a tree data struc ...
- [LintCode] Segment Tree Build II 建立线段树之二
The structure of Segment Tree is a binary tree which each node has two attributes startand end denot ...
- [LintCode] Segment Tree Build 建立线段树
The structure of Segment Tree is a binary tree which each node has two attributes start and end deno ...
- Segment Tree Modify
For a Maximum Segment Tree, which each node has an extra value max to store the maximum value in thi ...
- 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), ...
- Segment Tree Build I & II
Segment Tree Build I The structure of Segment Tree is a binary tree which each node has two attribut ...
- Lintcode: Segment Tree Query II
For an array, we can build a SegmentTree for it, each node stores an extra attribute count to denote ...
- Lintcode: Segment Tree Modify
For a Maximum Segment Tree, which each node has an extra value max to store the maximum value in thi ...
随机推荐
- Lucene.Net 2.3.1开发介绍 —— 简介
原文:Lucene.Net 2.3.1开发介绍 -- 简介 Lucene.Net是Lucene在dot net平台上的移植版本.它的功能与Lucene一样,都是用来提供一组API,让我们能快速开发自己 ...
- KVM 实现机制
1.1. KVM简介 KVM是一个基于Linux内核的虚拟机,它属于完全虚拟化范畴,从Linux-2.6.20开始被包含在Linux内核中.KVM基于x86硬件虚拟化技术,它的运行要求Intel ...
- C#数学运算表达式解释器
C#数学运算表达式解释器 測试文件内容: a=2+3*2; b=2*(2+3); 浏览按钮事件处理程序: private void button_browse_Click(object sender, ...
- Gradle学习之使用java plugin
请通过下面方式下载本系列文章的Github演示样例代码: git clone https://github.com/davenkin/gradle-learning.git Gradle最 ...
- 并发编程实践五:ReentrantLock
ReentrantLock是一个可重入的相互排斥锁,实现了接口Lock,和synchronized相比,它们提供了同样的功能.但ReentrantLock使用更灵活.功能更强大,也更复杂.这篇文章将为 ...
- CDOJ 1221 Ancient Go
题目链接:http://acm.uestc.edu.cn/#/problem/show/1221 题目分类:dfs 代码: #include<bits/stdc++.h> using na ...
- android JNI处理图片的例子
android JNI处理图片的例子 原地址:http://blog.csdn.net/xjwangliang/article/details/7065670 <pre class=" ...
- Dvtm -- 平铺式终端
Dvtm -- 平铺式终端_Linux伊甸园开源社区-24小时滚动更新开源资讯,全年无休! Dvtm -- 平铺式终端 关注我们: 如果你使用过 Dwn 或 Awesome 这种平铺式窗口管理器,一定 ...
- QML性能
1) Limit JavaScript a) inline JavaScript: 内联的JavaScript方法; 1. 将js方法放置在Element内部; 2. 尝试将语句写在一行内; ...
- 中科燕园GIS外包----机场project地理信息系统EGIS
对于大型机场建设project,不管project建设过程中.还是project建设完毕后.进入执行和维护阶段.必然要产生和使用到大量的各式各样的信息资料,包含project项目过程管理控制类文档,p ...