集训队专题(10)1002 A Simple Problem with Integers
来源:互联网 发布:mac os x 10.12.5 cdr 编辑:程序博客网 时间:2024/05/08 15:02
A Simple Problem with Integers
Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4985 Accepted Submission(s): 1569
Problem Description
Let A1, A2, ... , AN be N elements. You need to deal with two kinds of operations. One type of operation is to add a given number to a few numbers in a given interval. The other is to query the value of some element.
Input
There are a lot of test cases.
The first line contains an integer N. (1 <= N <= 50000)
The second line contains N numbers which are the initial values of A1, A2, ... , AN. (-10,000,000 <= the initial value of Ai <= 10,000,000)
The third line contains an integer Q. (1 <= Q <= 50000)
Each of the following Q lines represents an operation.
"1 a b k c" means adding c to each of Ai which satisfies a <= i <= b and (i - a) % k == 0. (1 <= a <= b <= N, 1 <= k <= 10, -1,000 <= c <= 1,000)
"2 a" means querying the value of Aa. (1 <= a <= N)
The first line contains an integer N. (1 <= N <= 50000)
The second line contains N numbers which are the initial values of A1, A2, ... , AN. (-10,000,000 <= the initial value of Ai <= 10,000,000)
The third line contains an integer Q. (1 <= Q <= 50000)
Each of the following Q lines represents an operation.
"1 a b k c" means adding c to each of Ai which satisfies a <= i <= b and (i - a) % k == 0. (1 <= a <= b <= N, 1 <= k <= 10, -1,000 <= c <= 1,000)
"2 a" means querying the value of Aa. (1 <= a <= N)
Output
For each test case, output several lines to answer all query operations.
Sample Input
4 1 1 1 1142 12 22 32 41 2 3 1 22 1 2 22 32 41 1 4 2 12 12 22 32 4
Sample Output
111113312341
Source
2012 ACM/ICPC Asia Regional Changchun Online
此题为区间更新,区间查询,但是在区间更新上,会有点要求,注意点就好
#include <cstdio>#include <cstring>#include <algorithm>#define LL __int64using namespace std;const int maxn = 50010;struct tree{ int l , r, k[12];}a[4*maxn];int num[maxn] , N , Q;void build(int l , int r , int k){ a[k].l = l; a[k].r = r; for(int i = 0; i < 12; i++) a[k].k[i] = 0; if(l != r){ int mid = (l+r)/2; build(l , mid , 2*k); build(mid+1 , r , 2*k+1); }}void update(int l , int r , int k , int lk , int lc){ if(l <= a[k].l && a[k].r <= r) a[k].k[lk] += lc; else{ int mid = (a[k].l+a[k].r)/2; if(mid >= r) update(l , r, 2*k , lk , lc); else if(mid < l) update(l , r , 2*k+1 , lk , lc); else{ update(l , mid , 2*k , lk , lc); int tl = mid+1+(lk-(mid+1-l)%lk)%lk; if(tl <= r) update(tl , r , 2*k+1 , lk , lc); } }}int getAns(int k , int i){ int ans = 0; for(int j = 1; j <= 10; j++){ if((i-a[k].l)%j == 0) ans += a[k].k[j]; } return ans;}int query(int l , int r , int k){ if(l <= a[k].l && a[k].r <= r) return getAns(k , l); else{ int mid = (a[k].l+a[k].r)/2; int ans = getAns(k , l); if(mid >= r) return ans+query(l , r , 2*k); else return ans+query(l , r , 2*k+1); }}int main(){ while(~scanf("%d" , &N)){ for(int i = 1; i <= N; i++) scanf("%d" , &num[i]); build(1 , N , 1); scanf("%d" , &Q); int op , la, lb , lk , lc; while(Q--){ scanf("%d" , &op); if(op == 1){ scanf("%d%d%d%d" , &la , &lb , &lk , &lc); update(la , lb , 1 , lk , lc); }else{ scanf("%d" , &la); printf("%d\n" , num[la]+query(la , la , 1)); } } } return 0;}
0 0
- 集训队专题(10)1002 A Simple Problem with Integers
- nbut线段树专题F - A Simple Problem with Integers
- 线段树专题 POJ3468 A Simple Problem with Integers
- A Simple Problem with Integers (2)
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- 密码技术
- eclipse 离线安装 svn
- maven环境下spring4+mybatis3+mysql配置
- linux软链接ln命令的用法
- 查看oracle数据库表空间
- 集训队专题(10)1002 A Simple Problem with Integers
- linux系统下tomcat的启动
- 彻底解决mysql中文乱码的办法
- CSS中你可能不知道的单位
- 微信公众帐号开发教程第17篇-应用实例之音乐搜索
- java.lang.IllegalArgumentException: column '_id' does not exist
- 系统运维
- The method xxxx of type xxxx must override a superclass method 解决方式
- Velocity模板_toolbox