Xtreme8.0 - Sum it up 水题

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;
}
posted @ 2016-10-12 23:34  qscqesze  阅读(283)  评论(0编辑  收藏  举报