HDU 4046 Panda (tree-like array)

Source: Internet
Author: User

PandaTime limit:10000/4000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2838 Accepted Submission (s): 945


Problem Descriptionwhen I wrote down this letter and you may have been on the airplane to U.S.
We have known for years, which had exceeded one-fifth of my whole life. I still remember the first time we went to the movies and the first time we went for a walk together. I still remember the smiling face you wore when you were dressing in front of the mirror. I Love your smile and your shining eyes. When you were with me, every second was wonderful.
The more expectation I had, the more disappointment I got. You said your would like to go to u.s.i know what do you really meant. I respect your decision. Gravitation is not a responsible for people falling. I'll always be your best friend. I know the is difficult. Every minute thinking of giving up, thinking of the reason why you had held on for a long, just keep going on. Whenever you ' re have a bad day, remember This:i love you.
I'll keep waiting, until you come back. Look into my eyes and you'll see how you mean to me.
There is a fortunate stories in my life:one was finally the time I love you exhausted. The other is a long time ago on a particular day I met you.
Saerdna.

It comes back to several years ago. I still remember your immature face.
The yellowed picture under the table might evoke the countless memory. The boy would keep the last appointment with the girl, miss the heavy rain in those years, miss the love in those years. Have tried to conquer the world, and only to find the "in the end" is the world. I want to tell you I didn ' t forget. Starry night, I'll hold you tightly.

Saerdna loves Panda so much, and also you know that Panda have both colors, black and white.
Saerdna wants to share him love with Panda, so he writes a love letter by just black and white.
The love letter is too long and Panda have not this much time to see the whole.
But it's easy-to-read the letter, because Saerdna hides he love in the letter by using the three continuous key words tha T is white, black and white.
But Panda doesn ' t know how many Saerdna's love there is in the letter.
Can you help Panda?

Inputan integer T means the number of test cases t<=100
For each test case:
First line is the integers n, m
n means the length of the letter, m means the query of the Panda. n<=50000,m<=10000
The next line had n characters ' B ' or ' W ', ' B ' means black, ' w ' means white.
The next m lines
Each line has a type
Type 0:answer How many love between L and R. (0<=l<=r<n)
Type 1:change the kth character to CH (0<=k<n and ch are ' B ' or ' W ')

Outputfor each test case, output the case number first.
The answer of the question.

Sample Input
2bwbwb0 0-1 5wbwbw0 0 0 2-2 B0 0 4

Sample Output
Case 1:1 1 case 2:2 1 1 0

Sourcethe 36th ACM/ICPC Asia regional Beijing site--online Contest

Test Instructions: There is a string sequence of length n, there are two types of operations 0 x y output xy between how many adjacent three characters are WBW strings. 1 x C Change the character in the sequence to C on position X.

#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < stdlib.h>using namespace Std;const int N = 50001;int n,m;int c[n];char str[n];int lowbit (int x) {return x& (-X);}    int getsum (int x) {int s = 0;        while (x>0) {s + = c[x];    X-= Lowbit (x); } return s;}        void Add (int x,int y) {while (x<=n) {c[x] + = y;    x + = Lowbit (x);    }}int Main () {int T;    scanf ("%d", &t);    int k = 0;        while (t--) {memset (c,0,sizeof (c));        memset (str,0,sizeof (str));        printf ("Case%d:\n", ++k);        scanf ("%d%d", &n,&m);        scanf ("%s", str);                for (int i=1;i<n-1;i++) {if (str[i-1] = = ' W ' && str[i] = = ' B ' && str[i+1] = = ' W ') {            Add (i,1);        }} int x, y, Z;        Char ss[10];            while (m--) {scanf ("%d", &x);                if (x = = 1) {scanf ("%d%s", &AMP;Y,SS); if (ss[0] == ' B ') {if (y-1>=0 && y+1<n && str[y] = = ' W ' && str[y-1] = = ' W ' &&                    STR[Y+1] = = ' W ') {Add (y,1);                        } if (y-2>=0 && str[y-1] = = ' B ' && str[y] = = ' W ' && str[y-2] = = ' W ') {                    Add (y-1,-1);                        } if (Y+2<n && str[y] = = ' W ' && str[y+1] = = ' B ' && str[y+2] = = ' W ') {                    Add (y+1,-1); }}else if (ss[0] = = ' W ') {if (y-1>=0 && y+1<n && str[y] = = ' B ' &amp                    ;& str[y-1] = = ' W ' && str[y+1] = = ' W ') {Add (y,-1);                        } if (y-2>=0 && str[y] = = ' B ' && str[y-1] = = ' B ' && str[y-2] = = ' W ') {                    Add (y-1,1); } if (Y+2<n && str[y] = = ' B ' && str[y+1] = = ' B ' && str[y+2] = = ' W ') {Add (y+1,1);            }} Str[y] = ss[0];                }else{scanf ("%d%d", &y,&z);                    if (z-y<=1) {printf ("0\n");                Continue                } int sum1 = Getsum (y);                int sum2 = Getsum (z-1);            printf ("%d\n", SUM2-SUM1); }}} return 0;}


Copyright NOTICE: This article is the original blogger article, if you have special needs, please contact Bo Master qq:793977586.

HDU 4046 Panda (tree-like array)

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.