bzoj 2276: [Poi2011]Temperature

bzoj 2276: [Poi2011]Temperature

大家好,又见面了,我是全栈君。

2276: [Poi2011]Temperature

Time Limit: 20 Sec  Memory Limit: 32 MB

Submit: 749  Solved: 344

[
Submit][
Status][
Discuss]

Description

The Byteotian Institute of Meteorology (BIM) measures the air temperature daily. The measurement is done automatically, and its result immediately printed. Unfortunately, the ink in the printer has long dried out… The employees of BIM however realised the fact only recently, when the Byteotian Organisation for Meteorology (BOM) requested access to that data.

An eager intern by the name of Byteasar saved the day, as he systematically noted down the temperatures reported by two domestic alcohol thermometers placed on the north and south outside wall of the BIM building. It was established decades ago by various BIM employees that the temperature reported by the thermometer on the south wall of the building is never lower than the actual temperature, while that reported by the thermometer on the north wall of the building is never higher than the actual temperature. Thus even though the exact temperatures for each day remain somewhat of a mystery, the range they were in is known at least.

Fortunately for everyone involved (except Byteasar and you, perhaps), BOM does not require exact temperatures. They only want to know the longest period in which the temperature was not dropping (i.e. on each successive day it was no smaller than on the day before). In fact, the veteran head of BIM knows very well that BOM would like this period as long as possible. To whitewash the negligence he insists that Byteasar determines, based on his valuable notes, the longest period in which the temperature could have been not dropping. Now this is a task that Byteasar did not quite expect on his BIM internship, and he honestly has no idea how to tackle it. He asks you for help in writing a program that determines the longest such period.

某国进行了连续n天的温度测量,测量存在误差,测量结果是第i天温度在[l_i,r_i]范围内。
求最长的连续的一段,满足该段内可能温度不降。

 

Input

In the first line of the standard input there is one integer n(1<=N<=1000000) that denotes the number of days for which Byteasar took notes on the temperature. The measurements from day are given in the line no.i+1 Each of those lines holds two integers, x and y (-10^9<=x<=y<=10^9). These denote, respectively, the minimum and maximum possible temperature on that particular day, as reported by the two thermometers.

In some of the tests, worth 50 points in total, the temperatures never drop below -50 degrees (Celsius, in case you wonder!) and never exceeds 50 degrees (-50<=x<=y<=50)  

 

 

 

第一行n
下面n行,每行l_i,r_i
1<=n<=1000000

Output

In the first and only line of the standard output your program should print a single integer, namely the maximum number of days for which the temperature in Byteotia could have been not dropping.

 

 

 

一行,表示该段的长度

Sample Input

6

6 10

1 5

4 8

2 5

6 8

3 5

Sample Output

4
bzoj 2276: [Poi2011]Temperature
bzoj 2276: [Poi2011]Temperature

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1000010;
int a[N],b[N],q[N],f[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d %d",&a[i],&b[i]);
    int tail=0,head=1,ans=0;
    f[0]=1;
    for(int i=1;i<=n;i++)
    {
        while(tail>=head&&a[q[tail]]<=a[i]) tail--;
        q[++tail]=i;
        f[i]=f[i-1];
        while(a[q[head]]>b[i]) f[i]=q[head++]+1;
    }
    for(int i=1;i<=n;i++) ans=max(ans,i-f[i]+1);
    printf("%d",ans);
    return 0;
}

View Code

单调队列!!!

difficult.

转载于:https://www.cnblogs.com/12fs/p/7545261.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/108152.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 《github一天一道算法题》:分治法求数组最大连续子序列和「建议收藏」

    《github一天一道算法题》:分治法求数组最大连续子序列和

    2022年1月29日
    95
  • 多参数sp_executesql 函数的使用范例

    多参数sp_executesql 函数的使用范例终于搞定sp_executesql包含输出的多参数的调用,网上竟然没有很好的参考   set@sql=Nselect@I_ZSL=sum(I_SL),@I_ZYZ=sum(I_YZ),@I_ZZJ=sum(I_LJZJ),@I_ZJZ=(sum(I_YZ)-sum(I_LJZJ))fromV_GZ_SGZ_GZINFO_TYBwhereV_DW_DM=

    2022年5月21日
    44
  • screentogif全屏录制_录屏转gif手机版

    screentogif全屏录制_录屏转gif手机版作者:虚坏叔叔博客:https://xuhss.com早餐店不会开到晚上,想吃的人早就来了!?ScreenToGif录制软件的通用设置,优化使用体验在写博客的过程中习惯使用ScreenToGif来录制操作。在当下个人计算机性能内存搓搓有余的情况下,如何能够让这款软件非常好用呢?一、快捷键设置1.快速后台启动录屏窗口通过设置Ctrl+Alt+R能够快速启动软件二、关闭软件不退出有时,我需要让这个软件一直在后台运行,因为这块软件占的内存并不是很大:我们希望一直在后台运行即使关闭了

    2022年9月20日
    0
  • js 除法 取整「建议收藏」

    js 除法 取整「建议收藏」1.丢弃小数部分,保留整数部分 js:parseInt(7/2) 2.向上取整,有小数就整数部分加1 js:Math.ceil(7/2) 3,四舍五入. js:Math.round(7/2) 4,向下取整 js:Math.floor(7/2)都是JS内置对象

    2022年6月21日
    99
  • 如何完全删除sql2012_如何完全删除mysql

    如何完全删除sql2012_如何完全删除mysql更新文章:由于楼主是在2017年写的内容,当时理解问题不深,可能就是稀里糊涂地解决掉了这个问题,把一些没有与SQL相关的东西都删除了,但那时并不影响到其他程序的运行状况。现如今更新下文章,为避免误导大家进行误删一些东西而存在其他问题的隐患。—感谢一位小伙伴的提醒。—更改时间:2019年3月19日工作忙,没能及时回复大家,请谅解!!卸载方法多种,但是通常会有卸载数据库不干净的情况。虽…

    2022年10月2日
    4
  • PyCharm 2022.01.12激活-激活码分享

    (PyCharm 2022.01.12激活)好多小伙伴总是说激活码老是失效,太麻烦,关注/收藏全栈君太难教程,2021永久激活的方法等着你。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html747EFQ8BIF-eyJsaWNlbnNlSWQi…

    2022年3月31日
    77

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号