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. 《Play for Java》学习笔记(二)基本的CRUD应用

    注解:  CRUD——Create,Retrieve, Update, Delete 文件结构

  2. C#识别验证码技术-Tesseract

    相信大家在开发一些程序会有识别图片上文字(即所谓的OCR)的需求,比如识别车牌.识别图片格式的商品价格.识别图片格式的邮箱地址等等,当然需求最多的还是识别验证码.如果要完成这些OCR的工作,需要你掌握 ...

  3. mysql 无法远程访问(授权也没办法,确切的说是因为只绑定了127IP)

    默认状况下,出于安全考虑,mysql数据库屏蔽了远程访问功能. 然而在许多状况下,你需要在家或者从web程序去访问远端数据库服务器,这就相当麻烦了. 第一步: 激活网络设置你需要编辑mysql配置文件 ...

  4. 安卓/res/menu/的使用

    <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http:/ ...

  5. S1:原型继承

    一.基本性质 function obj(){ this.name1 = '可以被delete删除'; } obj.prototype.name2 = '不能被delete删除'; obj.protot ...

  6. 数组越界保护与消息传递black机制

    数组越界保护if(index.row <= [array count]) 发送消息[[NSNotificationCenter defaultCenter]     postNotificati ...

  7. 1800: [Ahoi2009]fly 飞行棋

    #include<cstdio> #include<iostream> using namespace std; ],n,ans; int main() { scanf(&qu ...

  8. POJ 2739 Sum of Consecutive Prime Numbers 难度:0

    题目链接:http://poj.org/problem?id=2739 #include <cstdio> #include <cstring> using namespace ...

  9. java日期的运用(DateUtils工具类)

    public static void main(String[] args) { Date now = new Date(); SimpleDateFormat sd = new SimpleDate ...

  10. Oracle实现自增方式:序列+触发器

    Oracle不能像MySQL那样设置主键自增,Oracle用 <序列+触发器>的方式使数据表的一列或多列实现自增 序列sequence+触发器trigger:实现数据表S_DEPART中的 ...