This is not difficult, just look at the study have no idea chunked
Ideas: with a
ans[i][j]
to record allk=(1~5e5)
in alla[k]%i==j
and, at the time of the query can achieve complexity bit O (1)Of course, because a lot of data, can not be divided up into many pieces, but also is not necessary to be divided into many blocks, because if during the
2
time of the operation, ifx=1e5,y=1e5-1
, in the data range then only the number of five to meet the conditions, can each skippedx
counting the number of value and the operation:ll Ans=0; for(int i=y;i<=int(5e5);i+=x) Ans+=a[i]; cout<<Ans<<endl;
Also: also found, in line when the output transducer
cout<<'\n'
thancout<<endl
many pieces, even double the difference, becausecout<<endl
even empty the cache, it will be a little slow
Code:
// Created by CAD on 2019/8/24.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int blo=280;
const int maxn=5e5+5;
ll ans[blo+5][blo+5];
int a[maxn];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t; cin>>t;
while(t--)
{
int op,x,y; cin>>op>>x>>y;
if(op==1)
{
a[x]+=y;
for(int i=1;i<=blo;++i) ans[i][x%i]+=y;
}
else
{
if(x<=blo) cout<<ans[x][y]<<'\n';
else
{
ll Ans=0;
for(int i=y;i<=int(5e5);i+=x) Ans+=a[i];
cout<<Ans<<'\n';
}
}
}
return 0;
}