hdu5057 Argestes and Sequence sub-block

Source: Internet
Author: User

Time limit:5000/2500 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 857 Accepted Submission (s): 240


Problem descriptionargestes have a lot of hobbies and likes solving query problems especially. One day argestes came up with such a problem. You are given a sequence a consisting of N nonnegative integers, a[1],a[2],..., a[n]. Then there is M operation on the sequence. An operation can being one of the following:
S X y:you should set the value of A[x] to Y (in other words perform an assignment a[x]=y).
Q L R D P:among [L, R], L and R are the index of the sequence, how many numbers, the Dth digit of the numbers is P.
Note:the 1st digit of a number is the least significant digit.
Inputin The first line there was an integer T, indicates the number of test cases.
For each case, the first line contains-numbers n and m.the second line contains n integers, separated by space:a[1],a [2],..., a[n]-initial value of array elements.
Each of the next M lines begins with a character type.
If Type==s,there would be is both integers more in the line:x,y.
If Type==q,there would be is four integers more in the line:l R D P.

[Technical specification]
1<=t<= 50
1<=n, m<=100000
0<=a[i]<=2 -1
1<=x<=n
0<=y<=2 -1
1<=l<=r<=n
1<=d<=10
0<=p<=9
Outputfor operation Q, output a line contains the answer.
Sample Input15 710 14Q 1 5 2 1Q 1 5 1 0Q 1 5 1 1Q 1 5 3 0Q 1 5 3 1S 1 100Q 1 5 3 1
Sample Output511501
Sourcebestcoder Round #11 (Div. 2) before using the line segment tree has been MLE (before the code to see the memory limit, it would not be able to open up), know that can be done with the sub-block, and then see a sub-block problem, then think this problem is relatively simple ~num[b][a] [b] represents the number of all the numbers in block B in the number of a bit B, which can be simply preprocessed, and then just a single point of modification, compare the original value and the new value of the update on it.
#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 <=) {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 <=) {c1[cnt] = old% 10;        C2[CNT] = now% 10;        Old/= 10;        Now/= 10;    cnt++;            } for (int i = 1; i <=; ++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 sub-block

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.