Hdoj 5372 Segment Game tree array + discretization

Source: Internet
Author: User


Because the line length of this question is increment .... So:

Puzzle: For newly inserted segments, the query has a number of segments whose left endpoint is greater than or equal to the left end of the segment. The difference between the two is that the right end of the segment is larger than the right end of the segment. It's done with two tree-like arrays. Complexity of Time Nlog



Segment GameTime limit:3000/1500 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 975 Accepted Submission (s): 275


Problem Descriptionlillian is a clever girl so, she has lots of fans and often receives gifts from her fans.

One day Lillian gets some segments from his fans Lawson with lengths of ... And she intends to the display them by adding them to a number line. At the i-th add Operation,she would put the segment with a length of I on the number line. Every time she put the segment on the Line,she would count how many entire segments on that segment. During the operation, she may delete some segments on the line. (Segments is mutually independent)
Inputthere is multiple test cases.

The first line of all case contains a integer n-the number of operations (1<=n<= 2? ten 5 , ∑n <= 7? ten 5 )

Next n lines contain the descriptions of the Operatons,one operation per line. Each operation contains and integers a, b.

If A is 0,it means add operation this Lilian put a segment on the position B (|b|< ten 9 ) of the line.
(For the i-th add Operation,she would put the segment on [B,b+i] of the line, with length of I.)

If a is 1,it means delete operation that Lilian would delete the segment which was added at the b-th add operation.
Outputfor i-th case,the First line output, the test case number.

Then for each of the add operation,ouput how many entire segments on the segment which Lillian newly adds.
Sample Input
30 00 30 150 10 01 10 10 0

Sample Output
Case #1:000Case #2:0102Hintfor the second case in the Sample:at the first add Operation,lillian adds a segment [1 , 2] on the line. At the second add Operation,lillian adds a segment [0,2] on the line. At the delete Operation,lillian deletes a segment which added at the first add operation. At the third add Operation,lillian adds a segment [1,4] on the line. At the fourth add Operation,lillian adds a segment [0,4] on the line

Source2015 multi-university Training Contest 7


/* ***********************************************author:ckbosscreated time:2015 August 11 Tuesday 20:49 58 seconds file Name : hdoj5372.cpp************************************************ * * #include <iostream> #include <cstdio># Include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib > #include <vector> #include <queue> #include <set> #include <map>using namespace Std;const int maxn=200200;int n,nx;struct Cz{cz () {}cz (int _id,int _kind,int _left,int _right,int _del) {id=_id,kind=_kind,left=_ Left,right=_right,del=_del;} int Id,kind,left,right,del;} Cz[maxn];int Caru_left[maxn],caru_right[maxn],cr;int allnum[maxn*3],an;/***********************bit************** /int tree_left[maxn*3],tree_right[maxn*3];inline int lowbit (int x) {return x& (-X);} void Add (int* tree,int P,int v) {for (int i=p;i;i-=lowbit (i)) {tree[i]+=v;}} int sum (int* tree,int p) {int ret=0;for (int i=p;i<an+100;i+=lowbit) (i) {ret+=tree[i];} return ret;} int main () {//freopen ("In.txt", "R", stdin),//freopen ("OUT.txt", "w", stdout); int Cas=1;while (scanf ("%d", &n)!=eof {an=0; nx=1; cr=1;for (int i=0,kind,val;i<n;i++) {scanf ("%d%d", &kind,&val), if (kind==0) {int V1=val;int v2= VAL+NX;NX++;ALLNUM[AN++]=V1; Allnum[an++]=v2;cz[i]=cz (i,0,v1,v2,0); caru_left[cr]=v1; Caru_right[cr]=v2; cr++;} else if (kind==1) {Cz[i]=cz (i,1,-999,-999,val);}} Sort (Allnum,allnum+an); An=unique (Allnum,allnum+an)-allnum;//for (int i=0;i<an;i++) cout<<allnum[i]< < ","; Putchar (10); memset (tree_left,0,sizeof (Tree_left)), memset (tree_right,0,sizeof (tree_right));p rintf ("Case #%d:\n", cas++); int i=0;i<n;i++) {CZ cc=cz[i];if (cc.kind==0) {int l=lower_bound (allnum,allnum+an,cc.left)-allnum+1;int R=lower_ Bound (allnum,allnum+an,cc.right)-allnum+1;int s1=sum (tree_left,l), int s2=sum (tree_right,r+1);p rintf ("%d\n", s1-s2 Add (tree_left,l,1); add (tree_right,r,1);} else if (cc.kind==1) {Cc.left=caru_left[cc.del];cc.right=caru_right[cc.del];intL=lower_bound (Allnum,allnum+an,cc.left)-allnum+1;int r=lower_bound (allnum,allnum+an,cc.right)-allnum+1;add (tree        _LEFT,L,-1); add (tree_right,r,-1);}}} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hdoj 5372 Segment Game tree array + discretization

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.