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)
blank

相关推荐

  • linux 实时查看日志 最新最后100行 tail「建议收藏」

    linux 实时查看日志 最新最后100行 tail「建议收藏」(1)实时查看日志文件tail-f日志文件名(2)只查看日志文件后100行tail-f-n100日志文件名(3)搜寻字符串grep‘搜寻字符串’日志文件名按ctrl+c退出————————————————版权声明:本文为CSDN博主「wanghai76」的原创文章,遵循CC4.0BY-SA版权协议,转载请附上原文出处链接及本声明。原文链接:http…

  • PreparedStatement类详解以及案例

    PreparedStatement类详解以及案例一:jdbc(1)注册驱动(2)获得链接:(3)获得sql容器:Statement:(4)执行sql语句:(5)查询操作,需要遍历结果集:(6)关闭资源:Statement:存在的弊端,可以被sql注入:所以实际开发是不在地用的**PreparedStatement:类:**作用:(1)带有预编译的功能:(2)效率高:(3)防止sql注入:传统…

  • Android中联系人使用

    我8月份的时候接触过联系人这里,看了很多文章,把我弄蒙了,今天突然发现这篇文章,不错,如果我以后涉及到这方面的业务,会多来学习下,作者博客地址和英文原文地址都放在最下面了。前阵子搞短信,发现Android1.x至2.0版本联系人数据库很多地方做了更改,且关于这方面的资料也比较少,所以找到一篇文章稍作翻译了下,以供大家参考,该文将分三部分发布。WorkingWithAndro

  • android开发之使用SQLite数据库存储

    SQLite 介绍SQLite 一个非常流行的嵌入式数据库,它支持 SQL 语言,并且只利用很少的内存就有很好的性能。此外它还是开源的,任何人都可以使用它。许多开源项目((Mozilla, PHP, Python)都使用了 SQLite.SQLite 由以下几个组件组成:SQL 编译器、内核、后端以及附件。SQLite 通过利用虚拟机和虚拟数据库引擎(VDBE),使调试、修改和扩展 SQL

  • DELL服务器数据恢复成功案例[通俗易懂]

    DELL服务器数据恢复成功案例[通俗易懂]DELLEqualLogicPS6100采用虚拟ISCSISAN阵列,为远程或分支办公室、部门和中小企业存储部署带来企业级功能、智能化、自动化和可靠性。以简化的管理、快速的部署及合理的价格满足了分支办公室和中小企业的存储需求,同时提供全套企业级数据保护和管理功能、可靠的性能、可扩展性和容错功能,是中型企业级存储的起点产品,但某些物理故障或其他操作都可能会对卷或存储造成破坏,因此对系列存储的数…

  • Linux下通配符总结

    Linux下通配符总结

发表回复

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

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