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. Java日期比较

    在进行业务处理时,遇到一个需要比较日期但是不包含时分秒的判断问题 SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd"); ...

  2. [整] Android ListView 去除边缘阴影、选中色、拖动背景色等

    以下是通过XML定义的方式实现,如果需要通过代码实现,找到对应是set方式设置即可. 去除ListView滑到顶部和底部时边缘的黑色阴影: android:fadingEdge="none& ...

  3. ASP.net学习总结

    学习ASP.net又一次接触了B/S开发.下面先通过一张图对ASP.net有一个宏观结构的总结.之后将详细介绍ASP.net中的六大对象. 1.Request从客户端得到数据,包括基于表单的数据和通过 ...

  4. 八、mini2440裸机程序之UART(1)简单介绍【转】

    转自:http://blog.csdn.net/shengnan_wu/article/details/8298869 一.概述          S3C2440通用异步接收和发送(UART)提供了三 ...

  5. GaN助力运营商和基站OEM实现5G sub-6GHz和mmWave大规模MIMO

    到2021年,估计全球会有更多的人拥有移动电话(55亿),将超过用上自来水的人数(53亿).与此同时,带宽紧张的视频应用将进一步增加对移动网络的需求,其会占移动流量的78%.使用大规模多输入多输出(M ...

  6. crontab挂定时任务

    Linux shell基本知识 a)">"  与 ">>"  的作用是不一样的,前者使用本次输出内容替换原有文件的内容,后者则是把本次输出追加 ...

  7. list的几种new方式比较ImmutableList

    数组的非空判断: -----数组的非空判断----- StringUtils.isNotBlank(array); list的非空判断: -----list的非空判断----- CollectionU ...

  8. 【论文阅读】Batch Feature Erasing for Person Re-identification and Beyond

    转载请注明出处:https://www.cnblogs.com/White-xzx/ 原文地址:https://arxiv.org/abs/1811.07130 如有不准确或错误的地方,欢迎交流~ [ ...

  9. git stash命令使用手册

    修改记录压栈保存: git stash push -u -m "msg" // -u ~ --意思是包含未被跟踪的文件git stash push -m "msg&quo ...

  10. 第四届CCF软件能力认证

    1.图像旋转 问题描述 旋转是图像处理的基本操作,在这个问题中,你需要将一个图像逆时针旋转90度. 计算机中的图像表示可以用一个矩阵来表示,为了旋转一个图像,只需要将对应的矩阵旋转即可. 输入格式 输 ...