1019

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

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define N 100010
#define LL long long
struct node
{
int d,id;
char c;
}li[N<<];
int q[N][],pp[N];
int s[N<<],cnt[N],cc[N];
void build(int l,int r,int w)
{
s[w] = ;
if(l==r-)
{
return ;
}
int m = (l+r)>>;
build(l,m,w<<);
build(m,r,w<<|);
}
void update(int a,int b,int d,int l,int r,int w)
{
if(a<=l&&b>=r)
{
s[w] = d;
return ;
}
if(l==r-)
return ;
if(s[w]>&&s[w]!=d)
{
s[w<<] = s[w<<|] = s[w];
s[w] = -;
}
int m = (l+r)>>;
if(a<=m)
update(a,b,d,l,m,w<<);
if(b>m)
update(a,b,d,m,r,w<<|);
}
void query(int l,int r,int w)
{
int i;
if(s[w]>)
{
for(i = l ; i < r; i++)
cnt[i] = s[w];
return ;
}
if(l==r-)
return ;
int m = (l+r)>>;
query(l,m,w<<);
query(m,r,w<<|);
}
bool cmp(node a,node b)
{
return a.d<b.d;
}
int main()
{
int i,n;
char c[];
scanf("%d",&n);
for(i = ; i < n ; i++)
{
scanf("%d%d%s",&q[i][],&q[i][],c);
if(c[]=='b')
cc[i+] = ;
else
cc[i+] = ;
li[*i].d = q[i][];
li[*i].id = -(i+);
li[*i+].d = q[i][];
li[*i+].id = i+;
}
sort(li,li+*n,cmp);
int tt = li[].d,g=;
for(i = ; i < *n ; i++)
{
if(li[i].d!=tt)
{
g++;
tt = li[i].d;
}
if(li[i].id<)
{
q[-li[i].id][] = g;
pp[g] = li[i].d;
}
else
{
q[li[i].id][] = g;
pp[g] = li[i].d;
}
}
build(,g,);
for(i = ; i <= g ; i++)
cnt[i] = ;
for(i = ; i <= n ; i++)
{
update(q[i][],q[i][],cc[i],,g,);
}
query(,g,);
int maxz=,ss,ee,ts,te;
cnt[] = ;
cnt[g+] = ;
pp[g+] = ;
for(i = ; i <= g ; i++)
{
if(cnt[i]!=)
continue;
ss = pp[i];
while(cnt[i]==&&i<=g)
i++;
ee = pp[i];
if(ee-ss+>maxz)
{
ts = ss;
te = ee;
maxz = ee-ss+;
}
}
printf("%d %d\n",ts,te);
return ;
}

1019.Line Painting(线段树 离散化)的更多相关文章

  1. [poj2528] Mayor's posters (线段树+离散化)

    线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayor ...

  2. D - Mayor's posters(线段树+离散化)

    题目: The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campai ...

  3. HDU5124:lines(线段树+离散化)或(离散化思想)

    http://acm.hdu.edu.cn/showproblem.php?pid=5124 Problem Description John has several lines. The lines ...

  4. hdu1542 矩形面积并(线段树+离散化+扫描线)

    题意: 给你n个矩形,输入每个矩形的左上角坐标和右下角坐标. 然后求矩形的总面积.(矩形可能相交). 题解: 前言: 先说说做这道题的感受: 刚看到这道题顿时就懵逼了,几何 烂的渣渣.后来从网上搜题解 ...

  5. 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)

    [POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

  6. Mayor's posters (线段树+离散化)

    Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...

  7. POJ 2528 Mayor's posters(线段树+离散化)

    Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...

  8. poj 2528 Mayor's posters(线段树+离散化)

    /* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...

  9. [UESTC1059]秋实大哥与小朋友(线段树, 离散化)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1059 普通线段树+离散化,关键是……离散化后建树和查询都要按照基本法!!!RE了不知道多少次………………我真 ...

随机推荐

  1. Java执行命令行脚本

    百度到的 Process p=Runtime.getRuntime().exec("C:\\test.cmd"); ProcessBuilder processBuilder=ne ...

  2. ecshop改造读写分离配置与改造

    前两天配置好了mysql主从方式,今天就拿ecshop练习读写分离.以下代码仅供学习参考,不成熟的地方,还需完善. <?php $db_name = "ecshop"; $p ...

  3. 使用urllib2的HttpResponse导致内存不回收(内存泄漏)

    问题出现环境:python 2.7.1(X)及以下, Windows(或CentOS) 这个问题产生在lib/urllib2.py的line 1174 (python 2.7.1),导致形成了cycl ...

  4. Spark Streaming揭秘 Day6 关于SparkStreaming Job的一些思考

    Spark Streaming揭秘 Day6 关于SparkStreaming Job的一些思考 Job是SparkStreaming的重要基础,今天让我们深入,进行一些思考. Job是什么? 首先, ...

  5. 1090. Highest Price in Supply Chain (25)

    时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...

  6. java优化占用内存的方法(一)

    java做的系统给人的印象是什么?占 内存!说道这句话就会有N多人站出来为java辩护,并举出一堆的性能测试报告来证明这一点.其实从理论上来讲java做的系统并不比其他语言开发出来的 系统更占用内存, ...

  7. 微软职位内部推荐-Principal Dev Manager for Windows Phone Shell

    微软近期Open的职位: Location: China, BeijingDivision: Operations System Group Engineering Group OverviewOSG ...

  8. git/ TortoiseGit 在bitbucket.org 使用证书登陆

    背景:使用https协议在bitbucket中进行pull,push 时每次都要输入密码,比较麻烦还耽误时间,在网上找了下保存密码的方式 使用在用户环境变量中配置_netrc 文件的方式(http:/ ...

  9. easyBCD安装双系统,简单便捷,亲测好用

    一 准备工作(在WIN7下操作完成) 1   从官网http://www.ubuntu.com/上下载镜像文件,大小接近700M.下载EasyBCD最新版安装之.特别声明:EasyBCD是一款很优秀的 ...

  10. JS中遍历普通数组和字典数组的区别

    // 普通数组 var intArray = new Array(); intArray[0] = "第一个"; intArray[1] = "第二个"; fo ...