题目大意
有一个包含500000个零的数组,给定两种操作
1、给定x , y 表示将a[ x ] += y
2、给定x , y 表示将数组a中下标模x等于y的元素累加并输出
思路:
显然对于 1 <= x <= k 有 k方中不同的询问,(x=3时有三种询问,(3,0)(3,1)(3,2)
,其他以此类推,相当于1到n的累和)
为了优化运行时间,我们可以预处理(算是预处理吧应该qwq)x较小的情况;
int sum[50100][5010];
int a[N];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
IO;
int n; cin >> n;
while(n--)
{
int op;
cin >> op;
int x, y;
cin >> x >> y;
if (op == 1)
{
a[x] += y;
for (int i = 1; i <= 1000; i++)
sum[i][x % i] += y;
}
else
{
if (x > 1000)
{
ll ans = 0;
for (ll i = y; i <= N-1; i += x)
ans = ans + a[i];
cout << ans << endl;
}
else
cout << sum[x][y] << endl;
}
}
return 0;
}