"codevs1690" Switch light segment tree interval modification + interval summation (Mark)

Source: Internet
Author: User

"codevs1690" Switch lightFebruary 15, 2014 4930 Title Description Description

Yyx House in front of the street has N (2<=n<=100000) lamp, before six o'clock in the evening, these lights are all closed, after six points, there will be M (2<=m<=100000) Individual press the switch, These switches can change the status of the light from the I lamp to the J lamp, and now Yyx want to know how much light is on from the X lamp to the y lamp (1<=i,j,x,y<=n)

Enter a description Input Description
line 1th: Two integers separated by spaces N and M 2..m+1: Each line represents an action, there are three integers separated by spaces: instruction Number (0 for press switch, 1 for inquiry status), X and Y
Output description Output Description

1th. Total number of queries: For each query, the result of the output query

Sample input Sample Input

4 5
0 1 2
0 2 4
1 2 3
0 2 4
1 1 4

Sample output Sample Output
1
2
Data range and Tips Data Size & Hint

There are 4 lights, 5 operations, the following is the status of each operation (x for closed, O for open):

Ooxx, Oxoo, XXXX---Ooxx inquiry 1~4

Code
1#include <cstdio>2#include <cmath>3#include <cstring>4#include <ctime>5#include <iostream>6#include <algorithm>7#include <Set>8#include <vector>9#include <queue>Ten#include <typeinfo> One#include <map> A#include <stack> -typedefLong Longll; - using namespacestd; the inline ll read () - { -ll x=0, f=1; -     CharCh=GetChar (); +      while(ch<'0'|| Ch>'9') -     { +         if(ch=='-') f=-1; ACh=GetChar (); at     } -      while(ch>='0'&&ch<='9') -     { -x=x*Ten+ch-'0'; -Ch=GetChar (); -     } in     returnx*F; - } to //************************************************************************************** + structSS - { the     intl,r,v; *     BOOLlazy; $}tr[100000*5];Panax Notoginseng intn,m; - voidBuildintKintSintt) the { +Tr[k].l=s; ATr[k].r=T; the     if(s==t) { +         return ; -     } $     intMid= (s+t) >>1; $Build (k<<1, s,mid); -Build (k<<1|1, mid+1, T); - } the voidPushdown (intK//set it up. - {Wuyi     if(!tr[k].lazy)return; thetr[k<<1].lazy=!tr[k<<1].lazy; -tr[k<<1|1].lazy=!tr[k<<1|1].lazy; Wutr[k<<1].v=tr[k<<1].r-tr[k<<1].l+1-tr[k<<1].v; -tr[k<<1|1].v=tr[k<<1|1].r-tr[k<<1|1].l+1-tr[k<<1|1].v; Abouttr[k].lazy=0; $ } - voidUpdateintKintSintt) - { - Pushdown (k); A     if(tr[k].l==s&&tr[k].r==t) +     { thetr[k].v=tr[k].r-tr[k].l+1-tr[k].v; -        if(TR[K].L!=TR[K].R) tr[k].lazy=1;//!!!!!!! $         return; the     } the     intMid= (TR[K].L+TR[K].R) >>1; the     if(t<=mid) Update (k<<1, s,t); the     Else if(s>mid) Update (k<<1|1, s,t); -     Else in     { theUpdate (k<<1, s,mid); theUpdate (k<<1|1, mid+1, T); About     } thetr[k].v=tr[k<<1].v+tr[k<<1|1].v; the } the intAskintKintSintt) + { - Pushdown (k); the     if(s==tr[k].l&&tr[k].r==t)Bayi     { the         returntr[k].v; the     } -     intMid= (TR[K].L+TR[K].R) >>1; -     if(T<=mid)returnAsk (k<<1, s,t); the     Else if(S>mid)returnAsk (k<<1|1, s,t); the     Else{ the         returnAsk (k<<1, S,mid) +ask (k<<1|1, mid+1, T); the     } - } the intMain () the { the 94scanf"%d%d",&n,&m); theBuild1,1, n); the      for(intI=1; i<=m;i++) the     {98         intt,x,y; Aboutscanf"%d%d%d",&t,&x,&y); -         if(t==0)101         {102Update1, x, y);103         }104         Elseprintf"%d\n", Ask (1, x, y)); the     }106     return 0;107}

"codevs1690" Switch light segment tree interval modification + interval summation (Mark)

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.