http://acm.hdu.edu.cn/showproblem.php?pid=5086

求所有连续区间的数字和

本质是一个乘法原理,当前位置的数字出现次数=这个数之前的数字个数*这个数之后的数字个数(均包括当前数字本身),注意i*(n-i+1)会超int

#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <cmath> using namespace std; typedef __int64 ll; const ll mod=; int main(){
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
ll ans=;
for(int i=;i<=n;i++){
ll x;
scanf("%I64d",&x);
ans=(ans+(ll)i*(n-i+)%mod*x%mod)%mod;
}
printf("%I64d\n",ans);
}
return ;
}

HDU 5086的更多相关文章

  1. hdu 5086 数列连续和求和

    http://acm.hdu.edu.cn/showproblem.php?pid=5086 求一段数列里面所有连续和的和,卡精度 规律很明显,数列里面每个数都被加了i*(n+1-i)次 注意下精度即 ...

  2. hdu 5086 Revenge of Segment Tree(BestCoder Round #16)

    Revenge of Segment Tree                                                          Time Limit: 4000/20 ...

  3. hdu 5086(递推)

    Revenge of Segment Tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  4. [ACM] HDU 5086 Revenge of Segment Tree(全部连续区间的和)

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

  5. HUD 5086 Revenge of Segment Tree(递推)

    http://acm.hdu.edu.cn/showproblem.php?pid=5086 题目大意: 给定一个序列,求这个序列的子序列的和,再求所有子序列总和,这些子序列是连续的.去题目给的第二组 ...

  6. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  8. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. 从 bcp 客户端收到一个对 colid x 无效的列长度。

    出现场景: 批量插入数据的时候出现这个问题. 原因分析:某个数据的长度应该是大于这个数据对应的列的定义长度. 所以一一检查到底是那个列的长度超出了. 第一种方法: ——————————2017-1-3 ...

  2. C++统计一段文字中各单词出现的频率

    #include <iostream> using namespace std; /* run this program using the console pauser or add y ...

  3. JavaScript之模块化编程

    前言 模块是任何大型应用程序架构中不可缺少的一部分,模块可以使我们清晰地分离和组织项目中的代码单元.在项目开发中,通过移除依赖,松耦合可以使应用程序的可维护性更强.与其他传统编程语言不同,在当前Jav ...

  4. JDE处理选项

    处理选项为JDE的一种数据结构,命名方式如下: The name of a data structure can be a maximum of characters-only if you begi ...

  5. 动态加载的数据,hover效果

    $('.option li').live('mouseenter',function(){            $(this).addClass("active");       ...

  6. 免费提供一些公开的SOCK4/5/HTTP/HTTPS代理服务器(经测试可以用)

    Last update IP address Port Country Type Anonymity 54 secs 116.228.55.217 8000 flag China HTTP High ...

  7. 类成员函数作为pthread_create函数参数

    from:http://www.cnblogs.com/shijingxiang/articles/5389294.html 近日需要将线程池封装成C++类,类名为Threadpool.在类的成员函数 ...

  8. EntityFramework之创建数据库及基本操作(一)

    那时学EF的时候还没有Code First,只有DB First,生成的是一个EDMX文件,Code First则没有这文件,下面直接上代码吧 数据库创建以及建表 1.首先我们新建一个新项目,使用Nu ...

  9. IBatis.Net 表连接查询(五)

    IBatis.Net之多表查询: 一.定制实际对应类的方式 首先配置多表的测试数据库,IBatis.Net之Oracle表连接查询配置: 首先新建两张表如下: 为两张表建立外键: ALTER TABL ...

  10. 第48套题【tarjan】【图&树的连通性】【并查集】

    Problem 1 图的连通性