codevs1191| Axis Dyeing | line tree

Source: Internet
Author: User

Title Description Description
There are N points on a line axis, respectively, 1~n. At first all the dots were dyed black. Then
we carry out m operations, and the first operation will [Li,ri] these dianran into white. Please output each operation after execution
the number of black dots remaining.
Enter a description input Description
Enter a behavior of N and M. The following m lines are two numbers per line Li, Ri
outputs description output Description
output M line, the number of black points remaining after each operation.
sample input to sample
Ten 3
3 3
5 7
2 8
sample output Sample outputs
9
6
3
Data Size & Hint
Data Limitations
1<=n<=2000,1<=m<=2000 for 30% of the data
1<=li<=ri<=n<=200000,1<=m<=200000 for 100% data

#include <iostream>#include<cstdio>using namespacestd;intx,y,n,m;structtree{intL,r,v;} t[800001];voidBuildintNowintXinty) {T[NOW].L=x; T[now].r=y; if(x==y) {t[now].v=1;return; } intMid= (x+y) >>1; Build ( Now<<1, X,mid); Build ( Now<<1|1, mid+1, y); T[NOW].V=t[now<<1].v+t[now<<1|1].v; }voidChangeintKintXinty) {    if(t[k].v==0)return; intL=t[k].l,r=T[K].R; if(L==x && r==y) {t[k].v=0;return; } intMid= (l+r) >>1; if(mid>=y) Change (k<<1, x, y); Else if(mid<x) Change (k<<1|1, x, y); Else{change (k<<1, X,mid); Change (k<<1|1, mid+1, y); } t[k].v=t[k<<1].v+t[k<<1|1].v;}intMain () {CIN>> N >>m; Build (1,1, N);  for(intI=1; i<=m; i++) {cin>> x >>y; Change (1, x, y); printf ("%d\n", t[1].v); }    return 0;}

codevs1191| Axis Dyeing | line tree

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.