Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >HDU 1199 Color the Ball

HDU 1199 Color the Ball

作者头像
ShenduCC
发布于 2018-04-27 03:00:40
发布于 2018-04-27 03:00:40
84600
代码可运行
举报
文章被收录于专栏:算法修养算法修养
运行总次数:0
代码可运行

Color the Ball

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 5631    Accepted Submission(s): 1395

Problem Description

There are infinite balls in a line (numbered 1 2 3 ....), and initially all of them are paint black. Now Jim use a brush paint the balls, every time give two integers a b and follow by a char 'w' or 'b', 'w' denotes the ball from a to b are painted white, 'b' denotes that be painted black. You are ask to find the longest white ball sequence.

Input

First line is an integer N (<=2000), the times Jim paint, next N line contain a b c, c can be 'w' and 'b'. There are multiple cases, process to the end of file.

Output

Two integers the left end of the longest white ball sequence and the right end of longest white ball sequence (If more than one output the small number one). All the input are less than 2^31-1. If no such sequence exists, output "Oh, my god".

Sample Input

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
3
1 4 w
8 11 w
3 5 b

Sample Output

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
8 11线段树区间覆盖的问题,问题是数字范围太大,所以要离散化。当然也可以不用离散化作,即动态开点。这道题目的测试数据比较弱,所以我用了动态开点,要是数据强一点,可能会内存超限,#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;
typedef long long int LL;
const int maxn=2*1e3;
LL mmax[maxn*35];
LL lmax[maxn*35];
LL rmax[maxn*35];
int c[maxn*35];
int l[maxn*35];
int r[maxn*35];
LL ll[maxn*35];
LL rr[maxn*35];
int n;
int p;
int newnode()
{
    l[p]=r[p]=-1;
    lmax[p]=rmax[p]=mmax[p]=0;
    ll[p]=rr[p]=-1;
    return p++;
}
void pushdown(int node,LL L,LL R)
{
    if(!(L==R))
    {
          if(l[node]==-1) l[node]=newnode();
        if(r[node]==-1) r[node]=newnode();
    }
    if(c[node]!=-1)
    {
        if(c[node])
        {
            lmax[node]=rmax[node]=mmax[node]=R-L+1;
            ll[node]=L,rr[node]=R;
        }
        else
        {
            lmax[node]=rmax[node]=mmax[node]=0;
            ll[node]=rr[node]=-1;
        }

        c[l[node]]=c[r[node]]=c[node];
        c[node]=-1;
    }
}
void pushup(int node,LL L,LL R)
{
    LL mid=(L+R)>>1;
    
    pushdown(l[node],L,mid);
    pushdown(r[node],mid+1,R);
    if(lmax[l[node]]==(mid-L+1))
        lmax[node]=lmax[l[node]]+lmax[r[node]];
    else
        lmax[node]=lmax[l[node]];
    if(rmax[r[node]]==(R-mid))
        rmax[node]=rmax[r[node]]+rmax[l[node]];
    else
        rmax[node]=rmax[r[node]];
    mmax[node]=max(lmax[r[node]]+rmax[l[node]],max(mmax[l[node]],mmax[r[node]]));
    if(mmax[node]==mmax[l[node]])
        ll[node]=ll[l[node]],rr[node]=rr[l[node]];
    else if(mmax[node]==lmax[r[node]]+rmax[l[node]])
        ll[node]=mid-rmax[l[node]]+1,rr[node]=mid+lmax[r[node]];
    else
        ll[node]=ll[r[node]],rr[node]=rr[r[node]];

}

void update(int node,LL begin,LL end,LL L,LL R,int tag)
{

    if(L<=begin&&end<=R)
    {
        c[node]=tag;
        if(l[node]==-1) l[node]=newnode();
        if(r[node]==-1) r[node]=newnode();
        pushdown(node,begin,end);
        return;
    }
    if(l[node]==-1) l[node]=newnode();
    if(r[node]==-1) r[node]=newnode();
    pushdown(node,begin,end);
    int mid=(begin+end)>>1;

    if(L<=mid) update(l[node],begin,mid,L,R,tag);
    if(R>mid) update(r[node],mid+1,end,L,R,tag);
    pushup(node,begin,end);
}
int main()
{

    while(scanf("%d",&n)!=EOF)
    {
        p=0;
        int root=newnode();
        LL a,b;
        char cc;
        LL len=(1<<31)-1;
        int tag;
        update(root,1,len,1,len,0);
        memset(c,-1,sizeof(c));
      for(int i=1;i<=n;i++)
        {
            scanf("%lld%lld %c",&a,&b,&cc);
            if(cc=='w') tag=1;
            else tag=0;
            update(root,1,len,a,b,tag);
        }
        if(ll[root]==-1)
            printf("Oh, my god\n");
        else
            printf("%lld %lld\n",ll[root],rr[root]);
    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-10-29 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
HDU 4348 To the moon(可持久化线段树)
To the moon Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 4287    Accepted Submission(s): 923 Problem Description Background To The Moon is a independent game released in November 2011, it is
ShenduCC
2018/04/27
6970
HDU 4605 Magic Ball Game(可持续化线段树,树状数组,离散化)
Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2489    Accepted Submission(s): 759 Problem Description When the magic ball game turns up, Kimi immediately falls in it. The inter
ShenduCC
2018/04/27
6680
HDU 5634 Rikka with Phi (线段树)
Problem Description Rikka and Yuta are interested in Phi function (which is known as Euler's totient function). Yuta gives Rikka an array  of positive integers, then Yuta makes  queries.   There are three types of queries:  Change  into ,
ShenduCC
2018/04/27
5770
给球上色(线段树+离散化) - HDU 1199
假定待离散化的序列为a[n],b[n]是序列a[n]的一个副本,则对应以上三步为:
ACM算法日常
2019/01/02
1.3K0
HDU 4417 Super Mario(线段树)
Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5370    Accepted Submission(s): 2461 Problem Description Mario is world-famous plumber. His “burly” figure and amazing jumping ability
ShenduCC
2018/04/27
6320
HDU 5877 2016大连网络赛 Weak Pair(树状数组,线段树,动态开点,启发式合并,可持久化线段树)
Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1468    Accepted Submission(s): 472 Problem Description You are given a  tree of  nodes, labeled from 1 to . To the th node a non-n
ShenduCC
2018/04/27
7210
HDU 3450 Counting Sequences(线段树)
Counting Sequences Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others) Total Submission(s): 2335    Accepted Submission(s): 820 Problem Description For a set of sequences of integers{a1,a2,a3,...an}, we define a sequence
ShenduCC
2018/04/27
5210
hdu 1394
求逆序数的时候,算出以每一个数为逆序数对的第二个数的情况之和即为序列的逆序数,这样能够防止反复
全栈程序员站长
2022/07/10
1850
[OI题库]八月提高模拟题解
具体地,将该点插入单调栈时,只会改变栈顶位置和插入点的值。记录原栈顶位置、插入点更改前的值,即可在回溯时撤销。
Clouder0
2022/09/23
2850
P2023 [AHOI2009]维护序列
老师交给小可可一个维护数列的任务,现在小可可希望你来帮他完成。 有长为N的数列,不妨设为a1,a2,…,aN 。有如下三种操作形式: (1)把数列中的一段数全部乘一个值; (2)把数列中的一段数全部加一个值; (3)询问数列中的一段数的和,由于答案可能很大,你只需输出这个数模P的值。 输入输出格式 输入格式: 第一行两个整数N和P( )。第二行含有N个非负整数,从左到右依次为a1,a2,…,aN, ( )。第三行有一个整数M,表示操作总数。从第四行开始每行描述一个操作,输入的操作有以下三种形式: 操作1
attack
2018/04/13
7610
BZOJ2752: [HAOI2012]高速公路(road)(线段树 期望)
Time Limit: 20 Sec  Memory Limit: 128 MB Submit: 1820  Solved: 736 [Submit][Status][Discuss] Description Y901高速公路是一条重要的交通纽带,政府部门建设初期的投入以及使用期间的养护费用都不低,因此政府在这条高速公路上设立了许多收费站。 Y901高速公路是一条由N-1段路以及N个收费站组成的东西向的链,我们按照由西向东的顺序将收费站依次编号为1~N,从收费站i行驶到i+1(或从i+1行驶到i)需要收取V
attack
2018/07/27
2630
CodeForces 19D Points (线段树+set)
D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coordinate system on it as
ShenduCC
2018/04/27
6640
HDU 3333 Turing Tree (线段树)
Turing Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4768    Accepted Submission(s): 1686 Problem Description After inventing Turing Tree, 3xian always felt boring when solving problems ab
ShenduCC
2018/04/27
5410
[Atcoder][CF]简单题选做练习笔记 2
第一个式子,要求 p_i \equiv 0 \pmod 3,第二个式子要求 p_i \equiv 1 \pmod 3 且 p_j \equiv 2 \pmod 3 或者反过来。
Clouder0
2022/09/23
3890
BZOJ3083: 遥远的国度(树链剖分)
以下图片来自(https://blog.csdn.net/lcomyn/article/details/45718295)
attack
2018/07/27
3230
BZOJ3083: 遥远的国度(树链剖分)
HDU6315 Naive Operations(线段树 复杂度分析)
设\(d_i\)表示\(i\)号节点还需要加\(d_i\)次才能产生\(1\)的贡献
attack
2018/10/08
4670
HDU6315 Naive Operations(线段树 复杂度分析)
SDUT算法分析与设计机测
将分解问题看成,以某个数字开头的分解有多少种,比如12可以看成以2开头的式子有几个,以3开头的有几个,4开头的有几个,6开头的有几个… 其中以2开头的分解式为例,可以看成12 = 2 * 6,即分析6有多少种分解方式,就是有多少个2开头的式子。
Here_SDUT
2022/09/19
5070
洛谷P3722 [AH2017/HNOI2017]影魔(线段树 set spaly)
题意 题目链接 Sol 这题好毒瘤啊。。 首先要观察到几个性质: 将最小值旋转到根相当于把右子树变为祖先的左子树,然后将原来的根变为当前最小值 上述操作对深度的影响相当于右子树不变,其他的位置-1 然后就可以做了,把询问离线之后离散化一下,建一棵权值线段树表示每个值对应的深度 同时用set维护出已经加入的值 每次先找到后继,看一下有没有左孩子,如果有的话说明前驱一定没有右孩子。 注意随时更新信息 复杂度\(O(nlogn)\) #include<bits/stdc++.h> #define Pair pa
attack
2019/03/08
3530
NOI 系列真题练习笔记
NOIP 前开始做做真题,虽然每年都风格迥异,不过感受一下 OI 风格的题目还是有一定意义的。
Clouder0
2022/09/23
8860
Day1下午解题报告
预计分数:0+30+30=60 实际分数:0+30+40=70 T1水题(water) 贪心,按长度排序, 对于第一幅牌里面的,在第二个里面,找一个长度小于,高度最接近的牌 进行覆盖。 考场上的我离正解只差一个小于号之遥。。。。。。。 1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 #include <iostream> 5 #include <set> 6 using namespace std; 7 i
attack
2018/04/11
7750
相关推荐
HDU 4348 To the moon(可持久化线段树)
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验