41 lines
1.0 KiB
C++
41 lines
1.0 KiB
C++
#include <algorithm>
|
|
#include <cassert>
|
|
#include <cmath>
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
#include <iostream>
|
|
using namespace std;
|
|
typedef long long LL;
|
|
typedef long double LDB;
|
|
const int kMaxN = 1e5 + 10;
|
|
int n, m, a[kMaxN];
|
|
LL small_bucket[400][400];
|
|
int main() {
|
|
#ifdef local
|
|
freopen("pro.in", "r", stdin);
|
|
#endif
|
|
scanf("%d%d", &n, &m);
|
|
for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); }
|
|
int boundary = sqrt(n);
|
|
assert(boundary < 400);
|
|
for (int i = 1; i <= n; i++)
|
|
for (int j = 1; j <= boundary; j++) small_bucket[j][i % j] += a[i];
|
|
while (m-- > 0) {
|
|
int opt, x, y;
|
|
scanf("%d%d%d", &opt, &x, &y);
|
|
if (opt == 1) {
|
|
if (x <= boundary) {
|
|
printf("%lld\n", small_bucket[x][y % x]);
|
|
} else {
|
|
LL res = 0;
|
|
for (int i = y; i <= n; i += x) res += a[i];
|
|
printf("%lld\n", res);
|
|
}
|
|
} else {
|
|
for (int i = 1; i <= boundary; i++) small_bucket[i][x % i] -= a[x];
|
|
a[x] = y;
|
|
for (int i = 1; i <= boundary; i++) small_bucket[i][x % i] += a[x];
|
|
}
|
|
}
|
|
return 0;
|
|
} |