题目大意:有$n$个数,两个操作
- $A;p;x:$询问当把第$i$个数放在第$imod p$个桶中时,第$x$个桶内数的和
- $C;x;y:$把第$x$个数改为$y$
题解:把每个$pleqslant sqrt n$的答案预处理出来,复杂度$O(nsqrt n)$。对于$p>sqrt n$的询问怎么办呢?暴力算,复杂度是$O(ndfrac{n}{p})$,因为$p>sqrt n$,所以$dfrac n p <sqrt n$,复杂度为$O(nsqrt n)$。修改也是暴力修改,复杂度为$O(sqrt n)$
卡点:无
C++ Code:
#include <cstdio> #define maxn 150010 #define sqn 388 int n, m; int s[maxn]; int V[400][400]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", s + i); for (int j = 1; j < sqn; j++) V[j][i % j] += s[i]; } while (m --> 0) { char op[10]; int x, y; scanf("%s%d%d", op, &x, &y); if (*op == 'A') { int ans = 0; if (x < sqn) ans = V[x][y]; else for (int i = y; i <= n; i += x) ans += s[i]; printf("%d ", ans); } else { int tmp = y - s[x]; s[x] = y; for (int i = 1; i < sqn; i++) V[i][x % i] += tmp; } } return 0; }