实习了一下,并未发现代码有什么问题,求解
#include<bits/stdc++.h>
using namespace std;
int s[1000010],h[100010],f,a,b,n,m;
inline void read(int &x)
{
x = 0;
int f = 1;
char s = getchar();
while(s < '0' || s > '9')
{
if(s == '-') f = -1;
s = getchar();
}
while(s >= '0' && s <= '9')
{
x = x * 10 + s - 48;
s = getchar();
}
x *= f;
return;
}
inline void write(int x)
{
if(x < 0)
{
putchar('-');
x *= -1;
}
if(x > 9) write(x / 10);
putchar(x % 10 + 48);
return;
}
int main()
{
read(n),read(m);
for(int i = 1;i <= n;i ++)
read(s[i]);
while(m --)
{
read(f);
if(f == 1)
{
read(a),read(b);
h[a] += b;
}
else
{
read(a);
int ans = s[a];
for(int i = 1;i * i <= a;i ++)
{
if(a % i == 0)
{
ans += h[i];
if(i != a / i) ans += h[a / i];
}
}
write(ans);
putchar('\n');
}
}
return 0;
}