Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5339 Accepted Submission(s): 1693
#include <cstdio> #include <cstring> #define lowbit(x) (x)&(-x) const int MAXN = 50000+5; int num[MAXN]; int c[MAXN][11][11]; int n; void add(int x, int k, int mod, int val) { for(int i = x; i <= n; i += lowbit(i)) c[i][k][mod] += val; } int sum(int x, int a) { int ret = 0; for(int i = x; i > 0; i -= lowbit(i)) for(int j = 1; j <= 10; ++j) ret += c[i][j][a%j]; return ret; } int main() { while(~scanf("%d", &n)){ for(int i = 1; i <= n; ++i) scanf("%d", &num[i]); memset(c, 0, sizeof(c)); int q, a, b, k, c, op; scanf("%d", &q); while(q--){ scanf("%d", &op); if(op == 1){ scanf("%d%d%d%d", &a, &b, &k, &c); add(a, k, a%k, c); add(b+1, k, a%k, -c); } else{ scanf("%d", &a); printf("%d\n", num[a]+sum(a, a)); } } } return 0; }
HDU 4267 A Simple Problem with Integers
原文:http://www.cnblogs.com/inmoonlight/p/5854477.html