SHOI 2009 Venue Reservation Balance Tree STL Practice

Source: Internet
Author: User

Title Description

PP building has an empty auditorium, which can provide meeting space for enterprises or units. Most of these meetings require a few days in a row (individual may only take one day), but there is only one venue, so different meeting time applications cannot conflict. In other words, the end date of the previous meeting must precede the start date of the next meeting. Therefore, if you want to accept a new venue reservation application, you must reject the reservation that conflicts with this application. Generally speaking, if the PP building has already accepted a venue reservation, for example from 10th to 15th, it will not accept conflicting appointments, such as from 12th to 17th. Sometimes, however, in the interests of the economy, pp building sometimes refuses to make a reservation for a new venue, or even a few reservations. So, the auditorium administrator QQ notebook on the notebook often record such information: In the case for convenience, all dates are represented by an integer. For example, if a 10-day meeting starts at "90 days" and "99 Days", the next meeting can start at "100 Days" at the earliest. Recently, the work of this business is increasing, the auditorium of the Administrator QQ hope to participate in SHTSC you design a computer system for him to facilitate his work. The system should be able to perform the following two operations: a operation: A new appointment is from "Start Day" to "End Day" and rejects all conflicting appointments. When performing this operation, your system should return the number of appointments rejected for this new appointment, so that it is easy for QQ to proofread its own records. B Action: Ask your system to return the total number of appointments that are still valid.

Input/output format

Input format:

The first line of the input file is an integer n, which indicates the total number of operations your system will accept. Next n rows each row represents an action. Each row is formatted as one of the following: "A start end" represents a operation; "B" represents a B operation.

Output format:

The output file has n rows, one input per line at a time. Represents the return value of your system for this operation.

Input and Output Sample input example # #:
6A 15A 19A, 17A, 99A, 12B
Sample # # of output:
002012
Description

n< = 200000

1< = Start End < = 100000

Click here to submit

With <set> built-in red-black tree. Recording interval

The interval is sorted by the left endpoint.

Because there are no overlapping intervals, so do what you want to do.

The code is as follows

#include <cstdio>#include<iostream>#include<Set>#definefor (i,x,y) for (int i=x;i<=y;++i)using namespacestd;structnode{intL,r; BOOL operator< (ConstNode &v)Const{if(L==V.L)returnr<v.r;returnl<V.l;}}; typedefSet<Node>:: iterator it;Set<Node>S;inlineChargetc () {CharC=getchar (); for(c;c!='A'&&c!='B'; C=getchar ());returnC;}intMain () {intN;SCANF ("%d",&N); For (I,1, N) {        CharC=getc (); if(c=='A')        {            inttans=0; intL,r; scanf ("%d%d",&l,&R); Node a=(Node) {l,r};  while(1) {It it=S.lower_bound (a); if(it->l<=a.r&&it->r>=a.l) {s.erase (it); Tans++;Continue; }                if(It!=s.begin ()) it--; if(it->l<=a.r&&it->r>=a.l) {s.erase (it); Tans++;Continue;                } S.insert (a);  Break; } printf ("%d\n", tans); }        Else{printf ("%d\n", S.size ()); }    }}

SHOI 2009 Venue Reservation Balance Tree STL Practice

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.