题目大意;说是可以吧一段区间变成白色或者黑色, 区间(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. 简单的背包问题(入门)HDU2602 HDU2546 HDU1864

    动态规划,我一直都不熟悉,因为体量不够,所以今天开始努力地学习学习. 当然背包从01开始,先选择了一个简单的经典的背包HDU2602. Many years ago , in Teddy's home ...

  2. 授权(Authorization)

    介绍 除了认证服务,laravel还提供了授权服务,laravel同样提供了一个简单的方式去组织授权的逻辑来控制资源的访问.我们提供了各种各样的方法协助你们组织授权的逻辑,这些都在下面的文档之中. 定 ...

  3. ES 的CRUD 简单操作(小试牛刀)

    URL的格式: http://localhost:9200/<index>/<type>/[<id>] 其中index.type是必须提供的. id是可选的,不提供 ...

  4. 《Velocity java开发指南》中文版(下)转载

    文章出自:http://sakyone.iteye.com/blog/524292 8.Application Attributes Application Attributes (应用程序属性)是和 ...

  5. python模块学习 logging

    1.简单的将日志打印到屏幕 import logging logging.debug('This is debug message') logging.info('This is info messa ...

  6. 【elasticsearch】(1)centos7 使用yum安装elasticsearch 2.X

    前言 elasticsearch(下面称为ES)是一个基于Lucene的搜索服务器(By 百度百科:查看).所以他需要java的环境即jdk,这里提供懒人一键安装方式 # yum install ja ...

  7. [转] CSS direction属性简介与实际应用 ---张鑫旭

    一.用的少并不代表没有用 至少,在我接触的这么多项目里,没有见到使用过CSS direction属性做实际开发的. 为什么呢?是因为direction长得丑吗? 虽然说direction确实其貌不扬, ...

  8. js 中对象--属性相关操作

    查询属性: 可以用 对象.属性 来查询属性和属性方法               或者                    对象[“属性”]  来查询属性和属性方法 演示代码: <script ...

  9. 帝国cms在任意位置调用指定id的栏目名称和链接

    注意,这个代码无须放在灵动标签中,直接写入模板相应的位置就行了.[1]调用栏目名称: <?=$class_r[栏目ID]['classname']?>   示例:<?=$class_ ...

  10. DataTable 无法转换的错误

    目前基本上检索都已经离不开Linq了.所以最近在Linq的过程中出现了一些意外情况,特此记录下来. 先描述一下场景: 有一个查询的要求是这样的,检索出Status > 1 的数据.因为要根据其他 ...