time limit per test : 4 seconds
memory limit per test : 512 megabytes
分数:2100
You are given an array consisting of 500000 integers (numbered from 1 to 500000). Initially all elements of are zero.
You have to process two types of queries to this array:
;
, where
is the set of all integers from 1 to 500000 which have remainder
modulo
. Can you process all the queries?
Input
The first line contains one integer — the number of queries.
Then lines follow, each describing a query. The -th line contains three integers and . If , then it is a query of the first type, , and . If , then it it a query of the second type, , and .
It is guaranteed that there will be at least one query of type .
Output
For each query of type
print one integer — the answer to it.
Example
Input
5
1 3 4
2 3 0
2 4 3
1 4 -4
2 1 0
Output
4
4
0
题意:
刚开始有一个长度为500000的全0序列,有两种操作,第一种是将
变为
,第二种是询问所有
的和,
题解:
首先第一种操作,单点修改,这个可以直接修改,然后对于操作2种所有
的情况,用
的时间来更新一下答案。
然后第二种操作,查询,如果
,那么可以直接查询之前预处理过的结果。
如果
,那么则可以直接枚举所有的
(数量不会超过
)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll sum[804][804];
ll a[500004];
int q;
int main(){
memset(sum,0,sizeof(sum));
memset(a,0,sizeof(a));
scanf("%d",&q);
while(q--){
int t,x,y;scanf("%d%d%d",&t,&x,&y);
if(t==1){
a[x]+=y;
for(int i=1;i<=800;i++)sum[i][x%i]+=y;
}
if(t==2){
if(x<=800){
printf("%lld\n",sum[x][y]);
}
else{
ll ans=0;
for(int i=y;i<=500000;i+=x)ans+=a[i];
printf("%lld\n",ans);
}
}
}
return 0;
}