0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-30 15:56:27 +00:00

P3396 哈希冲突

https://www.luogu.com.cn/record/76008232
This commit is contained in:
Baoshuo Ren 2022-05-19 11:59:55 +08:00
parent 0d6f09eb17
commit 47265ad1cc
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

53
Luogu/P3396/P3396.cpp Normal file
View File

@ -0,0 +1,53 @@
#include <cmath>
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1.5e5 + 5,
NS = 505;
int n, m, t, a[N], f[NS][NS];
char op;
int main() {
std::ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
t = std::ceil(std::sqrt(n));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= t; j++) {
f[j][i % j] += a[i];
}
}
for (int i = 1, x, y; i <= m; i++) {
cin >> op >> x >> y;
if (op == 'A') {
if (x <= t) {
cout << f[x][y % x] << endl;
} else {
int ans = 0;
for (int i = y; i <= n; i += x) {
ans += a[i];
}
cout << ans << endl;
}
} else { // op == 'C'
for (int j = 1; j <= t; j++) {
f[j][x % j] += (y - a[x]);
}
a[x] = y;
}
}
return 0;
}