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了不知道多少次………………我真 ...
随机推荐
- Android Google购买PHP服务器端验证(订阅购买和一次性购买)
一.订阅购买验证 android端采用google service account进行校验 1.打开https://cloud.google.com/console创建一个project: 2.打开p ...
- Cassandra1.2文档学习(18)—— CQL数据模型(下)
三.集合列 CQL 3 引入了一下集合类型: •set •list •map 在关系型数据库中,允许用户拥有多个email地址,你可以创建一个email_addresses表与users表存在一个多对 ...
- JavaScript笔记(一)
JavaScript组成 EcmaScript:核心部分 作为解释器.几乎没有兼容性问题 DOM:Document Object Model,操作HTML页面的入口.有些操作不兼容. BOM:Brow ...
- QQ聊天机器人for PHP版 (登录,收、发消息)
<?php include "http_no_cookie.class.php"; class qq { public $sid; public $http; public ...
- Ecshop与Jquery冲突的完美解决方案
ecshop把AJAX事件和JSON解析的模块放在common/transport.js之中,可以说它也有自己封装的一套工具,这其实是很正常的. 但恰恰的,在封装JSON各种方法的同时对objec ...
- RadComboBox的用法
AutoPostBack="true",自动回传数据,也就是自动刷新 <telerik:RadComboBox ID="rcbTeacherList" r ...
- Spark Streaming揭秘 Day30 集群模式下SparkStreaming日志分析
Spark Streaming揭秘 Day30 集群模式下SparkStreaming日志分析 今天通过集群运行模式观察.研究和透彻的刨析SparkStreaming的日志和web监控台. Day28 ...
- Beaglebone Back学习六(Can总线测试)
Can总线测试 1 Can总线 控制器局域网 (Controller Area Network, 简称 CAN 或 CANbus)是一种通信协议,其特点是允许网络上的设备直接互相通信,网络上不需要主机 ...
- wpf datagrid 行双击事件
Xaml: <DataGrid ItemsSource="{Binding SessionList}" Grid.Row="2" Grid.Column= ...
- Intel Edison的那些事:修改Edison的HTTP服务的页面
Intel Edison配置好之后,按住PWR键2-7秒(4秒恰到好处),就可以进入AP热点模式(此时,Arduino扩展板上的灯不停闪烁),可以将笔记本接入Edison的热点,然后在浏览器中访问“h ...