博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4267 A Simple Problem with Integers
阅读量:4935 次
发布时间:2019-06-11

本文共 2198 字,大约阅读时间需要 7 分钟。

A Simple Problem with Integers

Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 5339    Accepted Submission(s): 1693

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)
 

 

Output
For each test case, output several lines to answer all query operations.
 

 

Sample Input
4
1 1 1 1
14
2 1
2 2
2 3
2 4
1 2 3 1 2
2 1
2 2
2 3
2 4
1 1 4 2 1
2 1
2 2
2 3
2 4
 

 

Sample Output
1
1
1
1
1
3
3
1
2
3
4
1
 

 

Source
 
 
 
解析:55个树状数组。
 
 
 
#include 
#include
#define lowbit(x) (x)&(-x)const int MAXN = 50000+5;int num[MAXN];int c[MAXN][11][11];int n;void add(int x, int k, int mod, int val){ for(int i = x; i <= n; i += lowbit(i)) c[i][k][mod] += val;}int sum(int x, int a){ int ret = 0; for(int i = x; i > 0; i -= lowbit(i)) for(int j = 1; j <= 10; ++j) ret += c[i][j][a%j]; return ret;}int main(){ while(~scanf("%d", &n)){ for(int i = 1; i <= n; ++i) scanf("%d", &num[i]); memset(c, 0, sizeof(c)); int q, a, b, k, c, op; scanf("%d", &q); while(q--){ scanf("%d", &op); if(op == 1){ scanf("%d%d%d%d", &a, &b, &k, &c); add(a, k, a%k, c); add(b+1, k, a%k, -c); } else{ scanf("%d", &a); printf("%d\n", num[a]+sum(a, a)); } } } return 0;}

  

转载于:https://www.cnblogs.com/inmoonlight/p/5854477.html

你可能感兴趣的文章
两个常见的oracle索引
查看>>
一位有着工匠精神的博主写的关于IEnumerable接口的详细解析
查看>>
MySQL中特有的函数If函数
查看>>
安装Python3.6.2报错:zipimport.ZipImportError: can't decompress data; zlib not available
查看>>
【蓝桥杯】入门训练 Fibonacci数列
查看>>
实验十 指针2
查看>>
常见HTTP状态码
查看>>
vim 空格和换行的删除和替换
查看>>
ionic 入门学习
查看>>
[python]pickle和cPickle
查看>>
末日了,天是灰色的。
查看>>
Vuejs vm对象详解
查看>>
自定义RatingBar的一个问题(只显示显示一个星星)
查看>>
剑指Offer--二叉树的镜像
查看>>
PAT-BASIC-1031-查验身份证
查看>>
Python笔记5----集合set
查看>>
连连看小游戏
查看>>
js二级联动
查看>>
谜题32:循环者的诅咒
查看>>
RMI
查看>>