1019.Line Painting(线段树 离散化)
离散化都忘记怎么写了 注意两个端点 离散化后用线段树更新区间 混色为-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(线段树 离散化)的更多相关文章
- [poj2528] Mayor's posters (线段树+离散化)
线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayor ...
- D - Mayor's posters(线段树+离散化)
题目: The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campai ...
- HDU5124:lines(线段树+离散化)或(离散化思想)
http://acm.hdu.edu.cn/showproblem.php?pid=5124 Problem Description John has several lines. The lines ...
- hdu1542 矩形面积并(线段树+离散化+扫描线)
题意: 给你n个矩形,输入每个矩形的左上角坐标和右下角坐标. 然后求矩形的总面积.(矩形可能相交). 题解: 前言: 先说说做这道题的感受: 刚看到这道题顿时就懵逼了,几何 烂的渣渣.后来从网上搜题解 ...
- 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)
[POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS Memory Limit: 65536K Total Submiss ...
- Mayor's posters (线段树+离散化)
Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...
- POJ 2528 Mayor's posters(线段树+离散化)
Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...
- poj 2528 Mayor's posters(线段树+离散化)
/* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...
- [UESTC1059]秋实大哥与小朋友(线段树, 离散化)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1059 普通线段树+离散化,关键是……离散化后建树和查询都要按照基本法!!!RE了不知道多少次………………我真 ...
随机推荐
- Python Generators vs Iterators
http://stackoverflow.com/questions/2776829/difference-between-python-generators-vs-iterators iterato ...
- laravel扩展图片处理Intervention Image
github地址:https://github.com/Intervention/image
- (转载)根据数据字典表定义的表结构,生成创建表的SQL语句
<来源网址:http://www.delphifans.com/infoview/Article_221.html>根据数据字典表定义的表结构,生成创建表的SQL语句 //1. 类名:T ...
- SYBASE时间计算
以摘录了计算月初,月末,上月同日,下月同日,上年同日,下年同日(年有闰月问题),各种函数输出格式. 可以写到存储过程中也可单独使用. Sybase日期函数 文章分类:数据库 关键字: sybase日期 ...
- 【BZOJ2428】[HAOI2006]均分数据
Description 已知N个正整数:A1.A2.…….An .今要将它们分成M组,使得各组数据的数值和最平均,即各组的均方差最小.均方差公式如下: ,其中σ为均方差,是各组数据和的平均值,xi为第 ...
- 主题: 为kindsoft编辑器替换SyntaxHighlighter代码高亮,整合DEDECMS
作者: fmamcn, 发布日期: 2012-09-29 12:28:39, 浏览数: 1567 看了狼魂发表的将kindeditor中的代码高亮插件prettify换为SyntaxHighlight ...
- JQuery 知识点
1:animate 动画效果 $(function () { $(".sidebar-nav a").mouseover(function () { $(this).animate ...
- $.post()返回数据正常,但不执行success回调函数
今天遇到一特郁闷的问题,如题:$.post()返回数据正常,但不执行success回调函数.说它郁闷是因为没毕业之前就遇到过解决了,却没有记录下来,导致卡了一下午. 像这样,post返回数据正常,但却 ...
- Eat the Trees hdu 1693
Problem DescriptionMost of us know that in the game called DotA(Defense of the Ancient), Pudge is a ...
- BZOJ 3160 万径人踪灭 解题报告
这个题感觉很神呀.将 FFT 和 Manacher 有机结合在了一起. 首先我们不管那个 “不能连续” 的条件,那么我们就可以求出有多少对字母关于某一条直线对称,然后记 $T_i$ 为关于直线 $i$ ...