"CODEVS1191" axis dyeing

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

10 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;intsum,tot=0;structtreetype{intLeft,right;//interval [left,right]    intLptr,rptr;//child hands left and right    intSum//intervals and    intbj//Mark}t[2000000];voidBuildtree (intllintRR) {    intcur=++tot; T[cur]. Left=ll; T[cur]. right=RR; if(ll!=rr-1) {t[cur].lptr=tot+1; Buildtree (LL, LL+RR)/2); T[cur].rptr=tot+1; Buildtree (+ (LL+RR)/2, RR); T[cur].sum=t[t[cur].lptr].sum+t[t[cur].rptr].sum; }Elset[cur].sum=1;}voidUpdateintK//delay message Next pass{t[t[k].lptr].sum=0; t[t[k].rptr].sum=0;//empty left and right sub-ranget[t[k].lptr].bj=1; t[t[k].rptr].bj=1;//Pass Flagt[k].bj=0;//Clear Flag}voidChangeintKintllintRr//Modifying the value of an interval [LL,RR] element{    if(Ll<=t[k]. LEFT&AMP;&AMP;RR&GT;=T[K]. right)//Overwrite current interval{t[k].sum=0;//intervals and =0t[k].bj=1;//Set logo    }    Else    {        if(T[K].BJ) update (k);//Pass Modification        if(ll< (t[k). LEFT+T[K]. right)/2)//Modify left IntervalChange (T[K].LPTR,LL,RR); if(Rr> (t[k). LEFT+T[K]. right)/2)//Modify Right IntervalChange (T[K].RPTR,LL,RR); T[k].sum=t[t[k].lptr].sum+t[t[k].rptr].sum;//update intervals and    }}intQueryintKintllintRr//query [LL,RR] interval and{    if(Ll<=t[k]. LEFT&AMP;&AMP;RR&GT;=T[K]. right)returnt[k].sum; if(T[K].BJ) update (k);//Pass Modification    intans=0; if(ll< (t[k). LEFT+T[K]. right)/2) ans+=query (T[K].LPTR,LL,RR); if(Rr> (t[k). LEFT+T[K]. right)/2) ans+=query (T[K].RPTR,LL,RR); returnans;}intMain () {intN,tim,x,y; scanf ("%d%d",&n,&Tim); Sum=N; Buildtree (1, n+1);  for(intI=1; i<=tim;i++) {scanf ("%d%d",&x,&y); Change (1, x,y+1); printf ("%d\n", Query (1,1, n+1)); }    return 0;}

"CODEVS1191" axis dyeing

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.