Codevs 1191 axis dyeing interval update plus delay marker

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

Output description Output Description

Output m line, the number of black points remaining after each operation.

Sample input Sample Input

10 3
3 3
5 7
2 8

Sample output Sample Output


Data range and Tips 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

Train of thought: Change the value of interval to 0, seek interval and;
#include <iostream>#include<cstdio>#include<cmath>#include<string>#include<queue>#include<algorithm>#include<stack>#include<cstring>#include<vector>#include<list>#include<Set>#include<map>#defineTrue Ture#defineFalse flaseusing namespacestd;#definell Long LongintScan () {intres =0, ch;  while( ! (ch = getchar ()) >='0'&& CH <='9' ) )    {        if(ch = = EOF)return 1<< - ; } Res= CH-'0' ;  while(ch = getchar ()) >='0'&& CH <='9') Res= Res *Ten+ (CH-'0' ) ; returnRes;}struct  is{    intL,r; intnum; intlazy;} tree[200010*3];voidBuild_tree (intLintRintPOS) {TREE[POS].L=l; TREE[POS].R=R; Tree[pos].lazy=-1; if(l==r) {Tree[pos].num=1; //scanf ("%lld", &tree[pos].num);        return; }    intMid= (L+R)/2; Build_tree (L,mid,pos*2); Build_tree (Mid+1, r,pos*2+1); Tree[pos].num=tree[pos*2].num+tree[pos*2+1].num;}voidUpdateintLintRintChangeintPOS) {    if(tree[pos].l==l&&tree[pos].r==r) {Tree[pos].lazy=Change ; Tree[pos].num=0; return; }    if(tree[pos].lazy==0) {Tree[pos*2].num= (tree[pos*2].r+1-tree[pos*2].L) *Tree[pos].lazy; Tree[pos*2+1].num= (tree[pos*2+1].r+1-tree[pos*2+1].L) *Tree[pos].lazy; Tree[pos*2].lazy=Tree[pos].lazy; Tree[pos*2+1].lazy=Tree[pos].lazy; Tree[pos].lazy=-1; }    intMid= (TREE[POS].L+TREE[POS].R)/2; if(r<=mid) Update (L,r,change,pos*2); Else if(l>mid) Update (L,r,change,pos*2+1); Else{update (L,mid,change,pos*2); Update (Mid+1, r,change,pos*2+1); } tree[pos].num=tree[pos*2].num+tree[pos*2+1].num;}intQueryintLintRintPOS) {    //cout<<l<< "" <<r<< "" <<pos<<endl;    if(tree[pos].l==l&&tree[pos].r==R)returnTree[pos].num; if(tree[pos].lazy==0) {Tree[pos*2].num=0; Tree[pos*2+1].num=0; Tree[pos*2].lazy=0; Tree[pos*2+1].lazy=0; Tree[pos].lazy=-1; }    intMid= (TREE[POS].L+TREE[POS].R)/2; if(l>mid)returnQuery (l,r,pos*2+1); Else if(r<=mid)returnQuery (l,r,pos*2); Else    returnQuery (l,mid,pos*2) +query (mid+1, r,pos*2+1);}intMain () {intx,q,i,t;  while(~SCANF ("%d",&x) {scanf ("%d",&q); Build_tree (1X1);  while(q--)        {            intFlag,change=0, L,r; scanf ("%d%d",&l,&R); Update (L,r,change,1); printf ("%d\n", Query (1X1)); }    }    return 0;}
View Code

Codevs 1191 axis dyeing interval update plus delay marker

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: 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.