HDU 4267

简介: A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 323 Accepted Submission(s): 133 Problem Description Let A1, A2, .

A Simple Problem with Integers

Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 323 Accepted Submission(s): 133


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
 1 //原来我用插点问线做的,输出sum(temp) - sum(temp-1),一直tle 
 2 #include <stdio.h>
 3 #include <iostream>
 4 #include<string.h>
 5 using namespace std;
 6 
 7 const int MAXD = 50010;
 8 int N, M, d[100][MAXD], a[MAXD];
 9 
10 void insert(int k, int x, int v)
11 {
12      for(; x <= N; x += x & -x) 
13           d[k][x] += v;
14 }
15 
16 void init()
17 {
18     int i, j;
19      for(i = 1; i <= N; i ++)
20           cin>>a[i];
21      for(i = 0; i < 100; i ++) 
22           memset(d[i], 0, sizeof(d[i][0]) * (N + 1));
23 }
24 
25 int query(int id)
26 {
27     int i, k, x, ans = 0;
28     for(i = 1; i <= 10; i ++)
29     {
30         k = (i - 1) * 10 + id % i;
31         for(x = id; x > 0; x -= x & -x) 
32           ans += d[k][x];
33     }
34     return a[id] + ans;
35 }
36 
37 void solve()
38 {
39     int i, flag,temp;
40     int a, b, k, c;
41     cin>>M;
42     while(M--)
43     {
44         cin>>flag;
45         if(flag == 1)
46         {
47             cin>>a>>b>>k>>c;
48             b -= (b - a) % k;
49             insert(10 * (k - 1) + a % k, a, c);
50             if(b < N) insert(10 * (k - 1) + b % k, b + 1, -c);
51         }
52         else if(flag == 2)
53         {
54             cin>>temp;
55             cout<<query(temp)<<endl;
56         }
57     }
58 }
59 
60 int main()
61 {
62     while(cin>>N)
63     {
64         init();
65         solve();
66     }
67     return 0;
68 }

 

目录
相关文章
|
7月前
|
机器学习/深度学习 存储 人工智能
HDU - 5912——Fraction
HDU - 5912——Fraction
|
人工智能 Java
hdu 1712 ACboy needs your help
ACboy这学期有N门课程,他计划花最多M天去学习去学习这些课程,ACboy再第i天学习第j门课程的收益是不同的,求ACboy能获得的最大收益。
145 0
|
定位技术
hdu 4771 Stealing Harry Potter's Precious
点击打开链接 题意:题目给定一个n*m的地图,地图有一个起点标记为'@',还有'#'表示不能够走的,'.'表示可以走。给定k个点,问从起点开始把这k个点走过去的最小步数。
798 0
hdu 1892 See you~
点击打开hdu 1892 思路: 二维树状数组 分析: 1 题目给定4种操作:  S x1 y1 x2 y2 询问以(x1 , y1) - (x2 , y2)为对角线的矩形的面积,但是这个对角线不一定是正对角线。
1019 0
|
Java 测试技术
HDU 1847
Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3204    Accepted Submission(s): 2008 Problem Description 大学英语四级考试就要来临了,你是不是在紧张的复习?也许紧张得连短学期的ACM都没工夫练习了,反正我知道的Kiki和Cici都是如此。
854 0