ural1019 Line Painting

Line Painting

Time limit: 2.0 second
Memory limit: 64 MB
The segment of numerical axis from 0 to 109 is painted into white color. After that some parts of this segment are painted into black, then some into white again and so on. In total there have been made  N re-paintings (1 ≤  N ≤ 5000). You are to write a program that finds the longest white open interval after this sequence of re-paintings.

Input

The first line of input contains the only number  N. Next  N lines contain information about re-paintings. Each of these lines has a form:
ai bi ci
where  ai and  bi are integers,  ci is symbol 'b' or 'w',  aibici are separated by spaces. 
This triple of parameters represents repainting of segment from  ai to  bi into color  ci ('w' — white, 'b' — black). You may assume that 0 <  ai <  bi < 109.

Output

Output should contain two numbers  x and  y ( x <  y) divided by space(s). These numbers should define the longest white open interval. If there are more than one such an interval output should contain the one with the smallest  x.

Sample

inputoutput
4
1 999999997 b
40 300 w
300 634 w
43 47 b
47 634

 

分析:离散化+线段树+答案二分;

   坑点2个:一是要把0和1e9边界考虑到,二是要注意染色和答案都是左闭右开区间;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=2e4+10;
const int dis[4][2]={{0,1},{-1,0},{0,-1},{1,0}};
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p%mod;p=p*p%mod;q>>=1;}return f;}
int n,m,k,t,c[maxn],ma;
int ans[2];
struct Node
{
    int sum, lazy;
} T[maxn<<2];

void PushUp(int rt)
{
    T[rt].sum = T[rt<<1].sum + T[rt<<1|1].sum;
}

void PushDown(int L, int R, int rt)
{
    int mid = (L + R) >> 1;
    int t = T[rt].lazy;
    T[rt<<1].sum = t * (mid - L + 1);
    T[rt<<1|1].sum = t * (R - mid);
    T[rt<<1].lazy = T[rt<<1|1].lazy = t;
    T[rt].lazy = 0;
}

void Update(int l, int r, int v, int L, int R, int rt)
{
    if(l==L && r==R)
    {
        T[rt].lazy = v;
        T[rt].sum = v * (R - L + 1);
        return ;
    }
    int mid = (L + R) >> 1;
    if(T[rt].lazy) PushDown(L, R, rt);
    if(r <= mid) Update(l, r, v, Lson);
    else if(l > mid) Update(l, r, v, Rson);
    else
    {
        Update(l, mid, v, Lson);
        Update(mid+1, r, v, Rson);
    }
    PushUp(rt);
}
int Query(int l, int r, int L, int R, int rt)
{
    if(l==L && r== R)
    {
        return T[rt].sum;
    }
    int mid = (L + R) >> 1;
    if(T[rt].lazy) PushDown(L, R, rt);
    if(r <= mid) return Query(l, r, Lson);
    else if(l > mid) return Query(l, r, Rson);
    return Query(l, mid, Lson) + Query(mid + 1, r, Rson);
}
struct node
{
    int x,y;
    char b[2];
}a[maxn];
int main()
{
    int i,j;
    j=0;
    scanf("%d",&n);
    c[j++]=0,c[j++]=1e9-1;
    rep(i,1,n)scanf("%d%d%s",&a[i].x,&a[i].y,a[i].b),c[j++]=a[i].x,c[j++]=a[i].y,c[j++]=a[i].x-1,c[j++]=a[i].y-1;
    sort(c,c+j);
    int num=unique(c,c+j)-c;
    rep(i,1,n)
    {
        a[i].x=lower_bound(c,c+num,a[i].x)-c+1;
        a[i].y--;
        a[i].y=lower_bound(c,c+num,a[i].y)-c+1;
        Update(a[i].x,a[i].y,(a[i].b[0]=='b'),1,num,1);
    }
    rep(i,1,num)
    {
        int l=i,r=num;
        while(l<=r)
        {
            int mid=l+r>>1;
            if(Query(i,mid,1,num,1)==0)
            {
                if(ma<c[mid-1]-c[i-1]+1)
                {
                    ma=c[mid-1]-c[i-1]+1;
                    ans[0]=c[i-1];
                    ans[1]=c[mid-1]+1;
                }
                l=mid+1;
            }
            else r=mid-1;
        }
    }
    printf("%d %d\n",ans[0],ans[1]);
    //system("pause");
    return 0;
}

转载于:https://www.cnblogs.com/dyzll/p/5827677.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目标检测(Object Detection)是计算机视觉领域的一个核心问题,其主要任务是找出图像中所有感兴趣的目标(物体),并确定它们的类别和位置。以下是对目标检测的详细阐述: 一、基本概念 目标检测的任务是解决“在哪里?是什么?”的问题,即定位出图像中目标的位置并识别出目标的类别。由于各类物体具有不同的外观、形状和姿态,加上成像时光照、遮挡等因素的干扰,目标检测一直是计算机视觉领域最具挑战性的任务之一。 二、核心问题 目标检测涉及以下几个核心问题: 分类问题:判断图像中的目标属于哪个类别。 定位问题:确定目标在图像中的具体位置。 大小问题:目标可能具有不同的大小。 形状问题:目标可能具有不同的形状。 三、算法分类 基于深度学习的目标检测算法主要分为两大类: Two-stage算法:先进行区域生成(Region Proposal),生成有可能包含待检物体的预选框(Region Proposal),再通过卷积神经网络进行样本分类。常见的Two-stage算法包括R-CNN、Fast R-CNN、Faster R-CNN等。 One-stage算法:不用生成区域提议,直接在网络中提取特征来预测物体分类和位置。常见的One-stage算法包括YOLO系列(YOLOv1、YOLOv2、YOLOv3、YOLOv4、YOLOv5等)、SSD和RetinaNet等。 四、算法原理 以YOLO系列为例,YOLO将目标检测视为回归问题,将输入图像一次性划分为多个区域,直接在输出层预测边界框和类别概率。YOLO采用卷积网络来提取特征,使用全连接层来得到预测值。其网络结构通常包含多个卷积层和全连接层,通过卷积层提取图像特征,通过全连接层输出预测结果。 五、应用领域 目标检测技术已经广泛应用于各个领域,为人们的生活带来了极大的便利。以下是一些主要的应用领域: 安全监控:在商场、银行
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值