标签:
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int SIZE = 330; int n, m; int A[N]; int block[N / SIZE + 1][SIZE + 1]; int num[N / SIZE + 1][12][10]; void pre(int b, int j) { int *B = &block[b][0]; for(int i = 0; i < j; ++i) { int tmp = B[i]; int cnt = 1; while(cnt <= 10) { int x = tmp % 10; tmp /= 10; num[b][cnt][x]++; cnt++; } } } void init() { memset(num, 0, sizeof num); scanf("%d%d", &n, &m); int j = 0, b = 0; for(int i = 0; i < n; ++i) { scanf("%d", &A[i]); block[b][j] = A[i]; if(++j == SIZE) { pre(b, j); b++; j = 0; } } if(j) { pre(b, j); ++b; } } int get(int x, int d) { int cnt = 1; while(cnt < d) { x /= 10; cnt++; } return x % 10; } int query(int L, int R, int D, int p) { int res = 0; int lb = L / SIZE, rb = R / SIZE; if(lb == rb) { for(int i = L; i <= R; ++i) { if(get(A[i], D) == p) res++; } } else { for(int i = L; i < (lb + 1) * SIZE; ++i) if(get(A[i], D) == p) res++; for(int i = rb * SIZE; i <= R; ++i) if(get(A[i], D) == p) res++; for(int i = lb + 1; i < rb; ++i) res += num[i][D][p]; } return res; } void modify(int x, int y) { if(A[x] == y) return; int old = A[x], now = y, b = x / SIZE, cnt = 1; int c1[12], c2[12]; A[x] = y; while(cnt <= 10) { c1[cnt] = old % 10; c2[cnt] = now % 10; old /= 10; now /= 10; cnt++; } for(int i = 1; i <= 10; ++i) { if(c1[i] != c2[i]) { num[b][i][ c2[i] ]++; num[b][i][ c1[i] ]--; } } } int main() { int _; scanf("%d", &_); while(_ --) { init(); char op[2]; int L, R, D, P; while(m --) { scanf("%s", op); if(op[0] == ‘Q‘) { scanf("%d%d%d%d", &L, &R, &D, &P); L--; R--; printf("%d\n", query(L, R, D, P)); }else { scanf("%d%d", &D, &P); D--; modify(D, P); } } } return 0; }
hdu5057 Argestes and Sequence 分块
标签:
原文地址:http://www.cnblogs.com/orchidzjl/p/4906955.html