题目大意;说是可以吧一段区间变成白色或者黑色, 区间(0-10^9)初始都是白色,问经过n次操作以后最大的连续白色区间

Problem Description
The segment of numerical axis from 0 to 109 is painted into white color. After that some parts of this segment are painted into black, then some into white again and so on. In total there have been made N re-paintings (1 ≤ N ≤ 5000). You are to write a program that finds the longest white open interval after this sequence of re-paintings.
 

Input
The first line of input contains the only number N. Next N lines contain information about re-paintings. Each of these lines has a form:
ai bi ci
where ai and bi are integers, ci is symbol 'b' or 'w', aibici are separated by spaces. 
This triple of parameters represents repainting of segment from ai to bi into color ci ('w' white, 'b' black). You may assume that 0 < ai < bi < 109.
 

Output
Output should contain two numbers x and y (x < y) divided by space(s). These numbers should define the longest white open interval. If there are more than one such an interval output should contain the one with the smallest x.
 

Sample Input
input output
4 1 999999997 b 40 300 w 300 634 w 43 47 b 
47 634 
 
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
#define maxn 5000
struct node
{
    int L, R, color;
    int Mid(){return (L+R)/2;}
};
node a[maxn*4*2];
int point[maxn*2+10], npoint;
int maxv, minv, First, Last, color;
void BuildTree(int r, int L, int R);
void Insert(int r, int L, int R, int color);
void Query(int r);
int main()
{
    int N;
    while(scanf("%d", &N) != EOF)
    {
        int i, L[maxn+10], R[maxn+10], c[maxn+10];
        char ch;
        for(npoint=i=0; i<N; i++)
        {
            cin >> L[i] >> R[i] >> ch;
            c[i] = (ch == 'w' ? 0 : 1);
            point[npoint++] = L[i];
            point[npoint++] = R[i];
        }
        point[npoint++] = 0, point[npoint++] = 1000000000;
        sort(point, point+npoint);
        npoint = unique(point, point+npoint) - point;
        BuildTree(1, 0, npoint-1);
        for(i=0; i<N; i++)
        {
            L[i] = lower_bound(point, point+npoint, L[i]) - point;
            R[i] = lower_bound(point, point+npoint, R[i]) - point;
            Insert(1, L[i], R[i], c[i]);
        }
        maxv = minv = First = Last = 0;
        color = 0;
        Query(1);
        printf("%d %d\n", minv, maxv);
    }
    return 0;
}
void BuildTree(int r, int L, int R)
{
    a[r].L = L, a[r].R = R, a[r].color = 0;
    if(R - L == 1)return ;
    BuildTree(r*2, L, a[r].Mid());
    BuildTree(r*2+1, a[r].Mid(), R);
}
void Insert(int r, int L, int R, int C)
{
    if(a[r].color == C)return ;
    if(a[r].L == L && a[r].R == R)
    {
        a[r].color = C;
        return ;
    }
    if(a[r].color >= 0)
        a[r*2].color = a[r*2+1].color = a[r].color;
    a[r].color = -1;
    if(R <= a[r].Mid())
        Insert(r*2, L, R, C);
    else if(L >= a[r].Mid())
        Insert(r*2+1, L, R, C);
    else
    {
        Insert(r*2, L, a[r].Mid(), C);
        Insert(r*2+1, a[r].Mid(), R, C);
    }
}
void Query(int r)
{
    if(a[r].color == 0)
    {
        Last = a[r].R;
        if(color == 1)
        {
            color = a[r].color;
            First = a[r].L;
        }
        if(maxv-minv < point[Last] - point[First])
                maxv = point[Last], minv = point[First];
        return ;
    }
    if(a[r].color == 1)
    {
        color = 1;
        return ;
    }
    Query(r*2);
    Query(r*2+1);
}

Line Painting的更多相关文章

  1. ural1019 Line Painting

    Line Painting Time limit: 2.0 secondMemory limit: 64 MB The segment of numerical axis from 0 to 109  ...

  2. 1019.Line Painting(线段树 离散化)

    1019 离散化都忘记怎么写了 注意两个端点 离散化后用线段树更新区间 混色为-1  黑为2  白为1  因为N不大 最后直接循环标记这一段的颜色查找 #include <iostream> ...

  3. URAL 1019 - Line Painting

    跟前面某个题一样,都是区间染色问题,还是用我的老方法,区间离散化+二分区间端点+区间处理做的,时间跑的还挺短 坑爹的情况就是最左端是0,最右端是1e9,区间求的是开区间 #include <st ...

  4. Aizu The Maximum Number of Customers

    http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_5_A The Maximum Number of Customers Ide ...

  5. 线段树详解 (原理,实现与应用)(转载自:http://blog.csdn.net/zearot/article/details/48299459)

    原文地址:http://blog.csdn.net/zearot/article/details/48299459(如有侵权,请联系博主,立即删除.) 线段树详解    By 岩之痕 目录: 一:综述 ...

  6. CF448C Painting Fence (分治递归)

    Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...

  7. Codeforces Round #353 (Div. 2)Restoring Painting

    Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was sto ...

  8. hdu-4810 Wall Painting(组合数学)

    题目链接: Wall Painting Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  9. Codeforces Gym 100342C Problem C. Painting Cottages 转化题意

    Problem C. Painting CottagesTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

随机推荐

  1. 自定义Operation

    1.要自定义一个Operation 首先要创建一个继承于NSOperation的类. 2.在创建好的类的.h文件声明自定义的方法:-(instancetype)initWithDownLoadMess ...

  2. Java中报错No enclosing instance of type caiquan is accessible. Must qualify the allocation with an enclosing instance of type caiquan (e.g. x.new A() where x is an instance of caiquan).

    package test;import java.util.Scanner;import java.util.Random;public class caiquan { public static v ...

  3. 使用ArrayList对大小写字母的随机打印

    从a~z以及A~Z随机生成一个字母并打印:打印全部的字母 package com.liaojianya.chapter1; import java.util.ArrayList; /** * This ...

  4. 237. Delete Node in a Linked List(C++)

    237. Delete Node in a Linked Lis t Write a function to delete a node (except the tail) in a singly l ...

  5. C#后台程序与HTML页面中JS方法互调

    此方法适用于 C#中嵌入WebBrowser(浏览器) 通过浏览器中加载的页面与C#的后台代码进行交互. 一.C#程序 1.在C#窗体中添加WebBrowser(浏览器),将页面的URL添加到浏览器中 ...

  6. 《cut命令》-linux命令五分钟系列之十九

    本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...

  7. 【elasticsearch】(2)centos7 超简单安装elasticsearch 的监控、测试的集群工具elasticsearch head

    elasticsearch-head是elasticsearch(下面称ES)比较普遍使用的可监控.测试等功能的集群管理工具,是由H5编写的单独的网页程序.使用方法网上很多,这里教大家一个超简单安装h ...

  8. Linux Curses编程实现贪吃蛇

    curses库 简单而言,提供UNIX中多种终端 操作光标和显示字符 的接口.我们常见的vi就是使用curses实现的.现在一般都用ncurses库. Linux下curses函数库    Linux ...

  9. HDUOJ Clear All of Them I 状压DP

    Clear All of Them I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 122768/62768 K (Java/Oth ...

  10. Early 80386 CPUs

    Assembling a detailed and accurate history of the 80386, including a complete listing of all the &qu ...