HDU 3911 Black and White

Source: Internet
Author: User

Black and Whitetime limit:3000msmemory limit:32768kbthis problem'll be judged onHDU. Original id:3911
64-bit integer IO format: %i64d Java class name: Main There is a bunch of stones on the beach; Stone color is white or black. Little Sheep have a magic brush, she can change the color of a continuous stone, black to white, white to black. Little Sheep like black very much, so she want to know the longest period of consecutive black stones in a range [I, j].InputThere was multiple cases, the first line of each case was an integer n (1<= n <= 10^5), followed by n integer 1 or 0 (1 Indicates black stone and 0 indicates white stone), then was an integer M (1<=m<=10^5) followed by M operations forma Tted as X i j (x = 0 or 1), x=1 means change the color of stones in range[i,j], and x=0 means ask the longest period of CO Nsecutive black stones in range[i,j]OutputWhen x=0 output a number means the longest length of black stones in range [I,j].Sample Input
41 0 1 050 1 41 2 30 1 41 3 30 4 4
Sample Output
120
SourceMulti-university Training Contest 8-host by HUST problem solving: line tree ah ... Fortunately only one operation, flip ah ... is to give you two operations, 1 a b indicates that a B area inside the 01 is flipped, 0 A B indicates the output of a B continuous between the longest 1 how many
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =100010;4 structNode {5     intlsum[2],rsum[2],mx[2];6     BOOLlazy;7} tree[maxn<<2];8 voidPushup (intVintk) {9      for(inti =0; I <2; ++i) {TenTree[v].lsum[i] = tree[v<<1].lsum[i]; OneTree[v].rsum[i] = tree[v<<1|1].rsum[i]; A         if(Tree[v].lsum[i] = = k-(k>>1)) -Tree[v].lsum[i] + = tree[v<<1|1].lsum[i]; -         if(Tree[v].rsum[i] = = (k>>1)) theTree[v].rsum[i] + = tree[v<<1].rsum[i]; -Tree[v].mx[i] = max (tree[v<<1].mx[i],tree[v<<1|1].mx[i]); -Tree[v].mx[i] = max (tree[v].mx[i],tree[v<<1].rsum[i]+tree[v<<1|1].lsum[i]); -     } + } -  + voidChangeintv) { ASwap (tree[v].lsum[0],tree[v].lsum[1]); atSwap (tree[v].rsum[0],tree[v].rsum[1]); -Swap (tree[v].mx[0],tree[v].mx[1]); -Tree[v].lazy =!Tree[v].lazy; - } - voidPushdown (intv) { -     if(tree[v].lazy) { inChange (v<<1); -Change (v<<1|1); toTree[v].lazy =false; +     } - } the voidBuildintLintRintv) { *Tree[v].lazy =false; $     if(L = =R) {Panax Notoginseng         inttmp; -scanf"%d",&tmp); thetree[v].mx[0] = tree[v].lsum[0] = tree[v].rsum[0] = !tmp; +tree[v].mx[1] = tree[v].lsum[1] = tree[v].rsum[1] =tmp; A         return; the     } +     intMid = (L + R) >>1; -Build (l,mid,v<<1); $Build (mid+1,r,v<<1|1); $Pushup (V,r-l +1); - } - voidUpdateintLintRintLtintRtintv) { the     if(LT <= L && RT >=R) { - Change (v);Wuyi         return; the     } - Pushdown (v); Wu     intMid = (L + R) >>1; -     if(LT <= mid) Update (l,mid,lt,rt,v<<1); About     if(Rt > Mid) Update (mid+1,r,lt,rt,v<<1|1); $Pushup (V,r-l +1); - } - intQueryintLintRintLtintRtintv) { -     if(LT <= L && RT >= R)returntree[v].mx[1]; A Pushdown (v); +     intMid = (L + R) >>1, ret =0; the     if(LT <= mid) ret = max (Ret,query (l,mid,lt,rt,v<<1)); -     if(Rt > Mid) ret = max (Ret,query (mid+1,r,lt,rt,v<<1|1)); $     if(LT <= mid && rt >mid) theret = max (Ret,min (Mid-lt +1,tree[v<<1].rsum[1]) + min (rt-mid,tree[v<<1|1].lsum[1])); thePushup (V,r-l +1); the     returnret; the } - intMain () { in     intn,m,op,a,b; the      while(~SCANF ("%d",&N)) { theBuild1N1); Aboutscanf"%d",&m); the          while(m--){ thescanf" %d%d%d",&op,&a,&b); the             if(OP) Update (1, N,a,b,1); +             Elseprintf"%d\n", Query (1, N,a,b,1)); -         } the     }Bayi     return 0; the}
View Code

HDU 3911 Black and White

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.