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. bzoj千题计划257:bzoj4199: [Noi2015]品酒大会

    http://www.lydsy.com/JudgeOnline/problem.php?id=4199 求出后缀数组的height 从大到小枚举,合并 维护组内 元素个数,最大.次大.最小.次小 # ...

  2. 流媒体技术学习笔记之(十一)Windows环境运行EasyDarwin

    流媒体平台框架下载安装 Github下载 下载地址:https://github.com/EasyDarwin/EasyDarwin/releases 解压安装 选择Windows 安装平台的安装包( ...

  3. [iOS]Xcode处理过时方法的警告

    ####强迫症的福利, 有的时候, 我们特别讨厌Xcode中的代码警告, 以下就是遇到各种警告的时候的处理方法:(后续会一直更新) 产生警告的原因: 某些方法废弃了, 会产生警告! 样式: 处理方法: ...

  4. [软件]Xcode查找系统framework所在路径

    有的时候, 我们不小心改了头文件, 导致Xcode系统库被修改(改回去也不行) 假设我改的是UIKit.framework类库里面的一个文件, 那么你只需要从另一个好使的电脑上, 在这个路径找到UIK ...

  5. [整理]Error: [ngRepeat:dupes]的解决方法

    sdfsadf <div class="pageNum middle PT10"> <a href="javascript:void(0);" ...

  6. 菜鸟学习Spring Web MVC之一

    ---恢复内容开始--- 当当当!!沉寂两日,学习Spring Web MVC去了.吐槽:近日跟同行探讨了下,前端攻城师,左肩担着设计师绘图,右肩担着JAVA代码?!我虽设计过UI,但这只算是PS技巧 ...

  7. CentOS配置源

    一.源列表 aliyun源 #各系统版本repo文件对应的下载操作 CentOS wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.al ...

  8. 产品排序(2015 年北大自招夏令营) (与栈相关的区间DP)

    题面: \(solution:\) 又是一道\(DP\)的好题啊!状态并不明显,需要仔细分析,而且还结合了栈的特性! 做这一类题,只要出题人有点理想,一定会在栈的性质上做点文章,所以我们尽量围绕栈的性 ...

  9. oracle开机自启,开机自动关闭防火墙,开机监听自启

    1.修改oratab 2,修改rc.local 3.关闭防火墙,设置开机时清空所有规则 参考文章: 1.https://blog.csdn.net/weeknd/article/details/726 ...

  10. linux内存管理-内核用户空间 【转】

    转自:http://blog.chinaunix.net/uid-25909619-id-4491362.html 1,linux内存管理中几个重要的结构体和数组 page unsigned long ...