HDU 4553 appointment arrangement (two-dimensional line segment tree), hdu4553

Source: Internet
Author: User
Tags dota

HDU 4553 appointment arrangement (two-dimensional line segment tree), hdu4553
Problem Description the winter vacation is coming, and it's time for John and the goddess to date.
Although James is a kingdom coders, she is very active. The Goddesses often reply "Haha" enthusiastically after james speaks in the big section on the Internet. Therefore, James's favorite is dating the goddesses. At the same time, there are also many friends looking for him to open the dark, because the number is too large, how to arrange time has become a major concern for James.
We know that Xiao Ming has a total of T free time, during which many goddesses or friends will come to Xiao Ming.
As a master who once scored 71 points in anger in the operating system, Xiao Ming came up with an algorithm, that is, "first algorithm adaptation". According to the description in the operating system textbook, it is to find the top qualified continuous space allocated to each request, and James made a decision:
When a friend came to Tom, James made an appointment with Tom based on the "first adaptive algorithm". If yes, he would say "X, let's fly (here, X is the start time); otherwise, let's say "fly with yourself ";
When the Goddess came to Xiao Ming, she first used the "first adaptive algorithm". If she couldn't find it, James would face the risk of ignoring the conventions of all his friends, use "ignore the first adaptive algorithm of friends" again. If you find the algorithm twice, you can say "X, don't put my gezi" (here, X is the start time ), otherwise, let's say "wait for me"
Of course, we know that James is not a man with endless performance. If he has been dating the Goddess and has time left, he will still go to dota with his friends. (For example, James and xiaoxi have an appointment ~ 5. dota is played in this time unit. At this time, when the Goddess and James make an appointment for a period of 3, the final time is 1 ~ 3 James goes on a date with Goddess. After that, he goes to 4 ~ 5 and Tom dota)
James occasionally wants to learn new knowledge. At this time, James will clear all the scheduled time in a certain time range for learning and yell at "I am the hope of chinese chengxuyuan !! ", However, James is generally three minutes of popularity. If someone else makes a reservation, James will allocate time to learn new knowledge according to the unbearable loneliness.
Input the first behavior CASE, indicating that there is a CASE group of test data;
Each group of data starts with two integers T, N. T represents the total time, and N represents the number of reservation requests;
In the next N rows, each row represents an appointment of a goddess or a friend of the Foundation. "ns qt" represents a goddess who came to James for about a period of QT, "ds qt" indicates a request with the length of QT. Of course, it may be that James wants to learn more. "STUDY !! L r indicates clearing L ~ All requests within the R range.

[Technical Specification]
1. 1 <= CASE <= 30
2. 1 <= T, N <= 100000
3. 1 <= QT <= 110000
4. 1 <= L <= R <= T
For each case, the first line outputs "Case C:", which indicates the first case, and then N rows. Each row corresponds to the result of a request (refer to the description ).
Output sample (which can be copied here ):
"X, let's fly", "fly with yourself", "X, don't put my gezi", "wait for me ", "I am the hope of chinese chengxuyuan !!"
 
Sample Input

15 6DS 3NS 2NS 4STUDY!! 1 5DS 4NS 2
 
Sample Output
Case 1:1,let's fly4,don't put my geziwait for meI am the hope of chinese chengxuyuan!!1,let's fly1,don't put my gezi
Question: Chinese. Line Segment tree practice: two-dimensional, one-dimensional indicates the silk, one-dimensional represents the goddess. Through the question, we know that the goddess has an absolute advantage for diaosi, so for the update of diaosi, we only need to consider its first dimension, for the goddess, it is necessary to find it in the useless time when updating the silk. If it is not found, it will take up the time of the silk. That is to say, no matter which time the goddess occupies, the corresponding time periods of the Goddess and diaosi must be updated. This question is due to the need to find the endpoint, so it is necessary to merge the intervals.
# Include <cstdio> # include <cstring> # include <algorithm> # include <vector> # include <string> # include <iostream> # include <queue> # include <cmath> # include <map> # include <stack> # include <bitset> using namespace std; # define REPF (I, a, B) for (int I = a; I <= B; ++ I) # define REP (I, n) for (int I = 0; I <n; ++ I) # define CLEAR (a, x) memset (a, x, sizeof a) typedef long LL; typedef pair <int, int> p Il; const int maxn = 100000 + 10; int sum [2] [maxn <2], col [2] [maxn <2]; // sum [2] [I] and goddess, col = 1 indicates that there is a vacant int lsum [2] [maxn <2], rsum [2] [maxn <2]; int t, n, m; void pushup (int p, int rs, int s) {lsum [p] [rs] = lsum [p] [rs <1]; rsum [p] [rs] = rsum [p] [rs <1 | 1]; if (lsum [p] [rs <1] = (s-(s> 1 ))) lsum [p] [rs] + = lsum [p] [rs <1 | 1]; if (rsum [p] [rs <1 | 1] = (s> 1 )) rsum [p] [rs] + = rsum [p] [rs <1]; sum [p] [rs] = max (sum [p] [rs <1], sum [p] [rs <1 | 1]), Rsum [p] [rs <1] + lsum [p] [rs <1 | 1]);} void pushdown (int p, int rs, int s) {if (col [p] [rs]! =-1) {if (col [p] [rs] = 1) {sum [p] [rs <1] = lsum [p] [rs <1] = rsum [p] [rs <1] = (s-(s>> 1 )); sum [p] [rs <1 | 1] = lsum [p] [rs <1 | 1] = rsum [p] [rs <1 | 1] = (s> 1 ); col [p] [rs <1] = col [p] [rs <1 | 1] = 1; col [p] [rs] =-1 ;} else {sum [p] [rs <1] = lsum [p] [rs <1] = rsum [p] [rs <1] = 0; sum [p] [rs <1 | 1] = lsum [p] [rs <1 | 1] = rsum [p] [rs <1 | 1] = 0; col [p] [rs <1] = col [p] [rs <1 | 1] = 0; col [p] [rs] =-1 ;}}} void build (int p, int l, int r, int rs) {col [p] [rs] =-1; Sum [p] [rs] = lsum [p] [rs] = rsum [p] [rs] = r-l + 1; if (l = r) return; int mid = (l + r)> 1; build (p, l, mid, rs <1); build (p, mid + 1, r, rs <1 | 1);} void update (int p, int x, int y, int c, int l, int r, int rs) {if (l> = x & r <= y) {col [p] [rs] = c; if (c) sum [p] [rs] = lsum [p] [rs] = rsum [p] [rs] = r-l + 1; else sum [p] [rs] = lsum [p] [rs] = rsum [p] [rs] = 0; return;} pushdown (p, rs, r-l + 1); int mid = (l + r)> 1; if (x <= mid) update (p, x, y, c, l, mid, rs <1); if (Y> mid) update (p, x, y, c, mid + 1, r, rs <1 | 1); pushup (p, rs, r-l + 1);} int query (int p, int x, int l, int r, int rs) {if (l = r) return l; pushdown (p, rs, r-l + 1); int mid = (l + r)> 1; if (sum [p] [rs <1]> = x) return query (p, x, l, mid, rs <1 ); else if (rsum [p] [rs <1] + lsum [p] [rs <1 | 1]> = x) return mid-rsum [p] [rs <1] + 1; else return query (p, x, mid + 1, r, rs <1 | 1 ); pushup (p, rs, r-l + 1);} int main () {int x, l, r, ans; int cas = 1; char str [15]; Scanf ("% d", & t); while (t --) {scanf ("% d", & n, & m); build (0, 1, n, 1); build (1, 1, n, 1); printf ("Case % d: \ n", cas ++); while (m --) {scanf ("% s", str); if (str [0] = 'D') {scanf ("% D", & x ); if (sum [0] [1] <x) puts ("fly with yourself"); else {ans = query (0, x, 1, n, 1 ); printf ("% d, let's fly \ n", ans); update (0, ans, ans + X-1, 0, 1, n, 1 );}} else if (str [0] = 'n') {scanf ("% d", & x); if (sum [0] [1]> = x) {ans = query (0, x, 1, n, 1); printf ("% D, don't put my gezi \ n ", ans); update (0, ans, ans + X-1, 0, 1, n, 1); update (1, ans, ans + X-1, 0, 1, n, 1);} else {if (sum [1] [1]> = x) {ans = query (1, x, 1, n, 1); printf ("% d, don't put my gezi \ n", ans); update (0, ans, ans + X-1, 0, 1, n, 1 ); update (1, ans, ans + X-1, 0, 1, n, 1);} else puts ("wait for me ");}} else {scanf ("% d", & l, & r); puts ("I am the hope of chinese chengxuyuan !! "); Update (0, l, r, n, 1); update (1, l, r, n, 1) ;}} return 0 ;}


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.