voidinit(){ for (int i = 1; i <= n; ++i) cin >> a[i]; for (int j = 1; j <= n; ++j) for (int i = 1; i <= p; ++i) sum[i][j % i] += a[j]; }
voidsolve(){ char cmd; int x, y; cin >> cmd >> x >> y; if (cmd == 'A') { int ans = 0; if (x > p) for (int i = y; i <= n; i += x) ans += a[i]; else ans = sum[x][y]; cout << ans << endl; } else { for (int i = 1; i <= p; ++i) sum[i][x % i] += y - a[x]; a[x] = y; } }
int n, q, s, d, k, a[N]; int sum[N + p][p + 5], f[N + p][p + 5];
voidinit(){ cin >> n >> q; for(int i=1;i<=n+p;i++) for(int j=1;j<=p;j++) sum[i][j]=0,f[i][j]=0; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= p; ++i) { for (int j = n; j >= 1; j--) sum[j][i] = sum[j + i][i] + a[j], f[j][i] = f[j + i][i] + sum[j + i][i] + a[j]; } }
voidsolve(){ while (q--) { cin >> s >> d >> k; if (d <= p) { int last = s + d * k; if (last > n)cout << f[s][d] << ' '; else cout << f[s][d] - f[last][d] - sum[last][d]*k << ' '; } else { int ans = 0, cnt = 1; for (int i = s; i <= s+d*(k-1); i += d) ans += a[i] * cnt, cnt++; cout << ans << ' '; } } cout << endl; }