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. C#获取“所有用户桌面”的路径

    想用C#得到The All Users Desktop(Public\Desktop)的路径. 原来以为很简单,然而 Environment.GetFolderPath(Environment.Spe ...

  2. 一段画对角线的canvas代码,之前没有写过canvas代码,现在记录下来

    <canvas id="other" style="width:320px;height:320px;"></canvas> var o ...

  3. CURL模拟登陆

    index.html <a href="http://adtuu-server.com/login/login.php?auth_username=admin&auth_pas ...

  4. 64位CentOS 6.4下安装wine(32位)

    1. 到http://dl.fedoraproject.org/pub/epel/6/x86_64/repoview/epel-release.html下载epel-release-6-8.noarc ...

  5. javascript实现URL不缓存的方法

    <script> document.write("<s"+"cript type='text/javascript' src='/js/test.js? ...

  6. foxtable使用笔记

    1.设置关联表窗口的列的顺序:Tables("award.people").SetColVisibleWidth("name|100|sex|100|job|100|ag ...

  7. aliexpress 上传图

    首先,图片转化为字节流 public byte[] ImagefileToByte(string srcImagePath) { System.IO.MemoryStream m = new Syst ...

  8. Oracle中正则表达式的使用

    Oracle10开始支持正则表达式. ORACLE中的支持正则表达式的函数主要有下面四个: 1. REGEXP_LIKE :          与LIKE的功能相似 2. REGEXP_INSTR : ...

  9. 2016 系统设计第一期 (档案一)MVC bootstrap model弹出窗

    局部代码: <!-- 按钮触发模态框 --> <div style=""> <button class="btn btn-primary&q ...

  10. git - 必备指令

    1. 查看远程分支 加上-a参数可以查看远程分支,远程分支会用红色表示出来(如果你开了颜色支持的话): $ git branch -a master remote tungway v1. * zron ...