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

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • LM优化算法_lm算法内参计算

    LM优化算法_lm算法内参计算LM算法理论知识梯度下降高斯牛顿Levenberg–Marquardt算法框架算法的整体流程求解器update流程说明算法实现头文件cpp算法调用LM优化算法,是一种非线性优化算法,其可以看作是梯度下降和高斯牛顿法的结合。综合了梯度下降对初值不敏感和高斯牛顿在最优值附近收敛速度快的特点。本人非数学专业,且对算法理解可能不到位,详细的算法推导及各个优化算法之间的关系,非常推荐看**《METHODSFORNON-LINEARLEASTSQUARESPROBLEMS》**,其介绍更详细也更专业。

  • tkMapper的使用-超详细

    tkMapper的使用-超详细tkMapper已经完成了对单表的通用操作的封装,主要封装在Mapper接口和MysqlMapper接口中,因此我们如果要完成对单表的操作,只需要自定义dao接口继承这两个接口即可。增加方法在准备工作中已经完成,如果想了解此部分内容,可以向上进行查看,此处主要是添加功能的另一种实现————主键回填。注意在进行主键回填的时候,实体类中id必须要用@Id指定一下,要不然映射的时候找不到id;过程如下创建一个users对象,对象的id是需要修改的用户的id,其他信息是需要更改后的信息。…

  • app与后台交互之间的几种安全认证机制

    app与后台交互之间的几种安全认证机制

  • 语音合成学习(一)综述

    语音合成学习(一)综述一、资料推荐爱丁堡大学课程(全英文,有能力的推荐学习一遍):https://speech.zone/courses/speech-synthesis/TensorflowTTS(比较系统的开源项目):https://github.com/TensorSpeech/TensorFlowTTS二、基础概念介绍1、时域:波形的振幅、频率;2、频域:傅里叶变换:每个复杂的波形都可以由不同频率的正弦波组成;语谱(spectrum):描述了信号包含的频率成分和它们的幅度;语谱图(spectrogram

  • 高清视频编码格式_如何将高清视频转化为蓝光

    高清视频编码格式_如何将高清视频转化为蓝光收藏于2012-01-09迁移自个人百度空间—————————高清视频编码最常用的编码格式是MPEG2-TS、MPEG4、H.264和VC-1这四种算法。          MPEG2由MPEG(MovingPictureExpertsGroup)运动图像专家组制定,这是国际标准化组织(ISO)于1988年成立的专责制定有关运动压缩编码标…

  • STM32移植LWIP

    STM32移植LWIP本文使用的是STM32F207VCT6平台,MII接口的RTL8201EL网络芯片,LWIP版本是1.4.1基础工程是:已经实现了10ms定时,led灯1s闪烁,还有串口打印欢迎查看本文所在的系列,STM32的LWIP应用,点击跳转本文使用的IDE是IAR7.2,考虑到很多很使用Keil,本文末尾也有keil版本的说明添加以太网驱动库添加进工程,增加新库的头文件路径将LWIP源码放入目录中我们把s…

发表回复

您的电子邮箱地址不会被公开。

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