首页 > 代码库 > HDU5086:Revenge of Segment Tree(规律题)

HDU5086:Revenge of Segment Tree(规律题)

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

#include <iostream>#include <stdio.h>#include <math.h>#include <queue>#include <map>#include <stdlib.h>#include <algorithm>#include <string.h>#define mod 1000000007using namespace std;int n;__int64 a[447010];__int64 sum;int main(){    int T;    scanf("%d",&T);    while(T--)    {        sum=0;        scanf("%d",&n);        a[0]=0;        for(int i=1; i<=n; i++)        {            scanf("%I64d",&a[i]);        }        if(n==1)        {            printf("%I64d\n",a[1]);            continue;        }        else        {            for(int i=1; i<=n; i++)            {                sum=(sum+a[i]*i%mod*(n-i+1)%mod)%mod;            }        }        printf("%I64d\n",sum);    }    return 0;}

 

HDU5086:Revenge of Segment Tree(规律题)