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. Android Activity 注意笔记

    图1:Activity生命周期的简化图,就像一个阶梯金字塔.这图像表明每个状态中是怎么样使用回调函数使得恢复状态回到顶端,或者降低状态到达底部.Activity可以从Paused状态和stopped状 ...

  2. php Zend Opcache,xcache,eAccelerator缓存优化详解及对比

    XCACHE XCache 是一个开源的 opcode 缓存器/优化器, 这意味着他能够提高您服务器上的 PHP 性能. 他通过把编译 PHP 后的数据缓冲到共享内存从而避免重复的编译过程, 能够直接 ...

  3. 解决Win7系统安装时“安装程序无法定位现有 系统分区,也无法创建新的系统分区”提示

    第一步:U盘启动装系统时,格式化主分区的内容后出现上面的问题 第二步:重启机器,通过U 盘启动.进入win pe系统. 第三步:把windows 7的ISO镜像解压到电脑的非系统盘的其他硬盘上.如D: ...

  4. Django的templates模版

    前面介绍的都是django.http.HttpResponse 把内容直接返回到网页上,这次介绍通过渲染模版的方法来显示内容 步骤: 1.创建一个项目(略) 2.创建一个app(略) 3.添加项目到s ...

  5. crystal report format number

    ToText({#totalPrice}, 2,'.', ',')  &" €" http://crystaltricks.com/wordpress/?p=149

  6. willMoveToParentViewController 与 didMoveToParentViewController

    在iOS 5.0以前,我们在一个UIViewController中这样组织相关的UIView 在以前,一个UIViewController的View可能有很多小的子view.这些子view很多时候被盖 ...

  7. poj 3207 Ikki's Story IV - Panda's Trick (2-SAT)

    http://poj.org/problem?id=3207 Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 13 ...

  8. memcached 在window下的安装与使用

    memcached搭建缓存系统 一.概念 Memcached是danga.com(运营LiveJournal的技术团队)开发的一套分布式内存对象缓存系统,用于在动态系统中减少数据库负载,提升性能. 二 ...

  9. [machine learning] Loss Function view

    [machine learning] Loss Function view 有关Loss Function(LF),只想说,终于写了 一.Loss Function 什么是Loss Function? ...

  10. 关闭MyEclipse的Quick Update

    关闭MyEclipse的Quick Update, Windows > Preferences > MyEclipse > Community Essentials, 把选项 &qu ...