HDU4046 Panda (line segment tree)

Source: Internet
Author: User
Tags cmath

HDU4046 Panda (line segment tree)
PandaTime Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission (s): 3167 Accepted Submission (s): 1032

Problem Description When I wrote down this letter, you may have been on the airplane to U. S.
We have known for 15 years, which has exceeded one-second th of my whole life. I still remember the first time we went to the movies, 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 are with me, every second is wonderful.
The more expectation I had, the more disappointment I got. you said you wowould like to go to U. s. I know what you really meant. I respect your demo. gravitation is not responsible for people falling in love. I will always be your best friend. I know the way is difficult. every minute thinking of giving up, thinking of the reason why you have held on for so long, just keep going on. whenever you're having a bad day, remember this: I LOVE YOU.
I will keep waiting, until you come back. Look into my eyes and you will see what you mean to me.
There are two most fortunate stories in my life: one is finally the time I love you exhausted. the other is that long time ago on a particle 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 evke the countless memory. the boy will keep the last appointment with the girl, miss the heavy rain in those years, miss the love in those years. having tried to conquer the world, only to find that in the end, you are the world. I want to tell you I didn't forget. starry night, I will hold you tightly.

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

Input An integer T means the number of test case T <= 100
For each test case:
First line is two integers n, m
N means the length of the letter, m means the query of the Panda. n <= 50000, m <= 10000
The next line has n characters 'B' or 'W', 'B' means black, 'w' means white.
The next m lines
Each line has two type
Type 0: answer how many love between L and R. (0 <= L <= R Type 1: change the kth character to ch (0 <= k
Output For each test case, output the case number first.
The answer of the question.

Sample Input

2 5 2 bwbwb 0 0 4 0 1 3 5 5 wbwbw 0 0 4 0 0 2 0 2 4 1 2 B 0 4 

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

Source
# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      # Include
       
         # Include
        
          # Include
         
           # Include using namespace std; const double eps = 1e-6; const double pi = acos (-1.0); const int INF = 0x3f3f3f; const int MOD = 1000000007; # define ll long # define CL (a, B) memset (a, B, sizeof (a) # define MAXN 500010 struct node {int l, r, s ;} t [MAXN <2]; int a [MAXN]; // indicates whether wbwint n, m; void build (int l, int r, int I) exists) {t [I]. l = l; t [I]. r = r; if (l = r) {t [I]. s = a [l]; return;} int mid = (l + r)> 1; build (l, mid, I <1); build (mid + 1, r, I <1 | 1); t [I]. s = t [I <1]. s + t [I <1 | 1]. s;} void update (int x, int num, int I) {if (t [I]. l = t [I]. r) {t [I]. s = num; return;} int mid = (t [I]. l + t [I]. r)> 1; if (x <= mid) update (x, num, I <1); else update (x, num, I <1 | 1 ); t [I]. s = t [I <1]. s + t [I <1 | 1]. s;} int query (int l, int r, int I) {if (t [I]. l = l & t [I]. r = r) return t [I]. s; int mid = (t [I]. l + t [I]. r)> 1; if (r <= mid) return query (l, r, I <1); else if (l> mid) return query (l, r, I <1 | 1); else return query (l, mid, I <1) + query (mid + 1, r, I <1 | 1 );} int main () {int T; char str [MAXN]; int L, R, x, k; char ch; scanf ("% d", & T ); for (int cas = 1; cas <= T; cas ++) {scanf ("% d", & n, & m); scanf ("% s ", str); CL (a, 0); for (int I = 1; I
          
            R-1) puts ("0"); else printf ("% d \ n", query (L + 1, R-1, 1 ));} else {scanf ("% d % c", & x, & ch); if (str [x] = ch) continue; str [x] = ch; // note the boundary if (x> 1 & str [X-2] = 'W' & str [x-1] = 'B' & str [x] = 'W ') {if (a [x-1] = 0) // if it was not wbw before, after changing a character, it constitutes wbw update (x-1, 1, 1 ); a [x-1] = 1; // mark the point as wbw} else if (x> 1 & a [x-1] = 1) // before wbw, after changing a character, it must not be wbw {update (x-1, 0, 1); a [x-1] = 0 ;} /// The following is the same as the above. if (x> 0 & x
           
             0 & x
            
           
          
         
        
       
     
    
   
  
 

The 36th ACM/ICPC Asia Regional Beijing Site -- Online Contest
A string containing only w and B. Each time, the number of 'wbw 'strings contained in a range is output, or a character is changed. Analysis: single-point update and interval query of Line Segment trees. For the original string, an array is used to mark whether the left and right of the point constitute 'wbw '. The value is 1 and the value is 0. Ps: Some things do not directly get the answer. If you change your mind a little, the answer is very clear. The questions of the Line Segment tree are still too few.

Related Article

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.