- 按余数分组求(哈希冲突)
1
- @ 2026-8-2 11:53:39
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
const int N = 1.5e5 + 1;
int a[N];
const int B = 300;
int n, m, res[B + 1][B + 1];
int query(int x, int y) {
int ans = 0;
if (x > B) {
for (int i = y; i <= n; i += x) ans += a[i];
} else {
ans = res[x][y];
}
return ans;
}
void change(int x, int y) {
for (int i = 1; i <= B; i++) {
int j = x % i;
res[i][j] += y - a[x];
}
a[x] = y;
}
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int x = 1; x <= B; x++) {
for (int y = 0; y < x; y++) {
for (int i = y; i <= n; i += x) {
res[x][y] += a[i];
}
}
}
while (m--) {
char o; int x, y;
cin >> o >> x >> y;
if (o == 'A') {
cout << query(x, y) << '\n';
} else {
change(x, y);
}
}
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
/*
g++ -std=c++14 1.cpp -o 1 && 1 < in.txt > out.txt
g++ -std=c++17 1.cpp -o 1 && ./1 < in.txt > out.txt
*/
0 条评论
目前还没有评论...
信息
- ID
- 541
- 时间
- ms
- 内存
- MiB
- 难度
- 7
- 标签
- 递交数
- 42
- 已通过
- 12
- 上传者