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)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • 如何用python画一个心形图_python画心形名字

    如何用python画一个心形图_python画心形名字Python可以使用turtle库来画爱心。Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x、纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在这个平面坐标系中移动,从而在它爬行的路径上绘制了图形。实现代码如下:fromturtleimport*pensize(1)pencolor(‘red’)fillcolor(‘pink…

    2022年9月7日
  • linux启动nginx命令_linuxzip解压命令

    linux启动nginx命令_linuxzip解压命令1,首先找到nginx的安装目录whichnginx会找到对应的目录,如图2,查看进程是否存在ps-ef|grepnginx3,杀死进程kill-QUIT1282强制停止kill-912824,进入到nginx的sbin目录,启动nginxcd/usr/local/nginx/sbin/./nginx./nginx-sstop./nginx-squit./nginx-sreload4,但是上面这个..

    2022年10月6日
  • git取消跟踪已版本控制的文件

    git取消跟踪已版本控制的文件

    2021年11月22日
  • XLSTransformer生成excel文件案例

    XLSTransformer生成excel文件案例项目结构图:项目中所用到的jar,可以到http://www.findjar.com/index.x下载ExcelUtil类源码:packageutil;importjava.io.IOException;importjava.net.URL;importjava.util.HashMap;importjava.uti

    2022年7月24日
  • 【转】使用Chrome Frame,彻底解决浏览器兼容问题「建议收藏」

    【转】使用Chrome Frame,彻底解决浏览器兼容问题「建议收藏」本文转自http://www.ryanbay.com/?p=269,感谢该作者的总结 X-UA-Compatible是自从IE8新加的一个设置,对于IE8以下的浏览器是不识别的。通过在meta中设置X-UA-Compatible的值,可以指定网页的兼容性模式设置。在网页中指定的模式优先权高于服务器中(通过HTTPHeader)所指定的模式。兼容性模式设置优先级: metatag&gt;…

    2022年7月16日
  • 数据挖掘面试 150 道题(附答案)

    数据挖掘面试 150 道题(附答案)单选题1.某超市研究销售纪录数据后发现,买啤酒的人很大概率也会购买尿布,这种属于数据挖掘的哪类问题?(A)A.关联规则发现B.聚类C.分类D.自然语言处理2.以下两种描述分别对应哪两种对分类算法的评价标准?(A)(a)警察抓小偷,描述警察抓的人中有多少个是小偷的标准。(b)描述有多少比例的小偷给警察抓了的标准。A.Precision,…

    2022年6月26日

发表回复

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

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