# A Simple Problem with Integers

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

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

Recommend
liuyiding   |   We have carefully selected several similar problems for you:  4276 4274 4273 4272 4270

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=50005;
typedef long long ll;
int tr[maxn][11][10];
int arr[maxn];
int lowbit(int i)
{
return i&(-i);
}
int query(int n)
{
int sum=0;
for(int j=1;j<=10;j++)
{
for(int i=n;i>0;i-=lowbit(i))
{
sum+=tr[i][j][n%j];
}
}
return sum+arr[n];
}
void update(int a,int k,int c,int mod,int n)
{
for(int i=a;i<=n;i+=lowbit(i))
{
tr[i][k][mod]+=c;
}
}
int main()
{
int n,q,a,b,k,c,op;
while(~scanf("%d",&n))
{
memset(tr,0,sizeof(tr));
for(int i=1;i<=n;i++)
{
scanf("%d",&arr[i]);
}
scanf("%d",&q);
for(int i=1;i<=q;i++)
{
scanf("%d",&op);
if(op==2)
{
scanf("%d",&a);
printf("%d\n",query(a));
}
else
{
scanf("%d%d%d%d",&a,&b,&k,&c);
update(a,k,c,a%k,n);
update(b+1,k,-c,a%k,n);
}
}
}
return 0;
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120