Sum it up

题目连接:

https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/sum-it-up

Description

Minka is very smart kid who recently started learning computer programming.

His coach gave him a cyclic array A having N numbers, and he has to perform Q operations on this array.

In each operation the coach would provide him with a number X. After each operation, every element of the cyclic array would be replaced by the sum of itself and the element lying X positions behind it in the cyclic array. All these replacements take place simultaneously.

For example, if the cyclic array was [a, b, c, d], then after the operation with X = 1, the new array would be [a+d, b+a, c+b, d+c].

He needs to output the sum of the elements of the final array modulus 10^9+7.

He made a program for it but it's not very efficient. You know he is a beginner, so he wants you to make an efficient program for this task because he doesn't want to disappoint his coach.

Input

The first line of each test file contains a integer N (1 <= N <= 100000).

The next line contains N space separated integers which represent the elements of the cyclic array ( 1 <= Ai <= 10^9 ).

The third line contains a integer Q (0 <= Q <= 1000000) representing the number of operations that will be applied to the array.

Finally, Q lines follow, each one containing an integer X (0 <= X < N).

Output

Your program should output to the standard output stream the sum of the elements of the final array modulus 10^9+7.

Note: There is a newline character at the end of the last line of the output.

Sample Input

5

1 2 3 4 5

2

1

0

Sample Output

60

Hint

题意

给你n个数,然后有Q次操作

每次操作是让a[i]+=a[(i+x)%n]

最后问你所有数的和是多少

题解

一个个去想的话,感觉不可做

但是你从整体去思考的话,那么显然就是一个傻逼题了。

代码

#include<bits/stdc++.h>
using namespace std; const int maxn = 1e5+7;
const int mod = 1e9+7;
int a[maxn];
int main()
{
int n,m;scanf("%d",&n);
long long ans = 0,sum = 0;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i],sum%=mod;
}
scanf("%d",&m);
for(int i=1;i<=m;i++){
int x;
scanf("%d",&x);
sum=(sum+sum)%mod; }
cout<<sum<<endl;
}

Xtreme8.0 - Sum it up 水题的更多相关文章

  1. HDU5053the Sum of Cube(水题)

    HDU5053the Sum of Cube(水题) 题目链接 题目大意:给你L到N的范围,要求你求这个范围内的全部整数的立方和. 解题思路:注意不要用int的数相乘赋值给longlong的数,会溢出 ...

  2. hdu5003 Osu!排序实现水题

    Osu! is a famous music game that attracts a lot of people. In osu!, there is a performance scoring s ...

  3. ZOJ 2679 Old Bill ||ZOJ 2952 Find All M^N Please 两题水题

    2679:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1679 2952:http://acm.zju.edu.cn/onli ...

  4. Xtreme8.0 - Magic Square 水题

    Xtreme8.0 - Magic Square 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/ ...

  5. codeforces 577B B. Modulo Sum(水题)

    题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. poj1564 Sum It Up dfs水题

    题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...

  7. UVa 10970 - Big Chocolate 水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  8. SPOJ 3693 Maximum Sum(水题,记录区间第一大和第二大数)

    #include <iostream> #include <stdio.h> #include <algorithm> #define lson rt<< ...

  9. poj 1003:Hangover(水题,数学模拟)

    Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 99450   Accepted: 48213 Descri ...

随机推荐

  1. UVALive 6176 Faulhaber's Triangle

    题目链接 http://acm.sdibt.edu.cn/vjudge/ojFiles/uvalive/pdf/61/6177.pdf 题意是  给定一个数n,代表着一共有n个人,且他们的身高从1到n ...

  2. SSH 公钥登录

    一般使用SSH进行远程登录时需要提供密码,这也是我们所熟知的一种方式. 另外,就是通过公钥登录的方式,本文将简要介绍公钥登录的两种方法,建议使用方法二.本文也将简单演示公钥登录过程,以及强制使用公钥和 ...

  3. 扩展欧几里得(E - The Balance POJ - 2142 )

    题目链接:https://cn.vjudge.net/contest/276376#problem/E 题目大意:给你n,m,k,n,m代表当前由于无限个质量为n,m的砝码.然后当前有一个秤,你可以通 ...

  4. Oracle中Inventory目录作用以及如何重建此目录 oraInst.loc 文件

    inventory 英 [ˈɪnvəntri] 美 [ˈɪnvəntɔ:ri] n. 清查; 存货清单; 财产目录,财产目录的编制; 存货总值; vt. 盘存; 编制…的目录; 开列…的清单; 总结 ...

  5. synchronized和lock

    Synchronized  同步代码块 使用 monitorenter 和 moniterexit 指令实现, monitorenter指令插入到同步代码块的开始位置, moniterexit 指令插 ...

  6. 历数依赖注入的N种玩法

    历数依赖注入的N种玩法 在对ASP.NET Core管道中关于依赖注入的两个核心对象(ServiceCollection和ServiceProvider)有了足够的认识之后,我们将关注的目光转移到编程 ...

  7. 【LOJ】#2080. 「JSOI2016」病毒感染

    题解 那个限制表示一回头要治完前面的所有病人 我们处理一个g[i][j]表示治疗i到j的病人至少会死多少病人 \(g[i][j] = g[i + 1][j] + sum[i + 1,j] + min( ...

  8. ubuntu14.0安装ITK的步骤

    (1) sudo apt-get install cmake (2) sudo apt-get install cmake-curses-gui (3)下载安装包InsightToolkit-4.11 ...

  9. Codeforces 1028E Restore Array 构造

    我发现我构造题真的不会写, 想了好久才想出来.. 我们先把n = 2, 所有数字相等, 所有数字等于0的都特判掉. 找到一个b[ i ] > b[ i - 1 ]的位置把它移到最后一个位置, 并 ...

  10. 2018 Arab Collegiate Programming Contest (ACPC 2018) H - Hawawshi Decryption 数学 + BSGS

    H - Hawawshi Decryption 对于一个给定的生成数列 R[ 0 ] 已知, (R[ i - 1 ] * a + b) % p = R[ i ] (p 是 质数), 求最小的 x 使得 ...