当前位置:网站首页>Luogu p3522 [poi2011] TEM temperature solution
Luogu p3522 [poi2011] TEM temperature solution
2022-07-19 13:52:00 【q779】
Luogu P3522 [POI2011]TEM-Temperature Answer key
Topic link :P3522 [POI2011]TEM-Temperature
The question :
A country has carried out continuous n n n ( 1 ≤ n ≤ 1 , 000 , 000 1 \le n \le 1,000,000 1≤n≤1,000,000) Day temperature measurement , There is an error in the measurement , The result of the measurement is i i i The temperature is [ l i , r i ] [l_i,r_i] [li,ri] Within the scope of .
Find the longest continuous segment , The temperature may not drop in this section .
It is not difficult to find that the legal range is max { l i } > r i + 1 \max\{l_i\}>r_{i+1} max{ li}>ri+1
Consider monotonic queue maintenance maxima
Note that the answer should be updated with (i-1)-q[st]+1
Because if there's one l i l_i li Particularly large , Maintain the current legal l l l All give pop It fell off
The count should not be from now l i l_i li Start , But the last one to be pop Dropped
Use this way q[st] Just right ( My code is (l,r] Of )
Time complexity O ( n ) O(n) O(n)
Code :
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <random>
using namespace std;
// #define int long long
// #define INF 0x3f3f3f3f3f3f3f3f
namespace FastIO
{
#define gc() readchar()
#define pc(a) putchar(a)
#define SIZ (int)(1e6+15)
char buf1[SIZ],*p1,*p2;
char readchar()
{
if(p1==p2)p1=buf1,p2=buf1+fread(buf1,1,SIZ,stdin);
return p1==p2?EOF:*p1++;
}
template<typename T>void read(T &k)
{
char ch=gc();T x=0,f=1;
while(!isdigit(ch)){
if(ch=='-')f=-1;ch=gc();}
while(isdigit(ch)){
x=(x<<1)+(x<<3)+(ch^48);ch=gc();}
k=x*f;
}
template<typename T>void write(T k)
{
if(k<0){
k=-k;pc('-');}
static T stk[66];T top=0;
do{
stk[top++]=k%10,k/=10;}while(k);
while(top){
pc(stk[--top]+'0');}
}
}using namespace FastIO;
#define N (int)(1e6+15)
int n,st,en,res=1,l[N],r[N],q[N];
signed main()
{
read(n); st=en=1;
for(int i=1; i<=n; i++)
{
read(l[i]);read(r[i]);
while(st<en&&l[q[st+1]]>r[i])++st;
if(st<en)res=max(res,i-q[st]);
while(st<en&&l[q[en]]<l[i])--en;
q[++en]=i;
}
write(res);
return 0;
}
Reprint please explain the source
边栏推荐
- Onvif protocol related: 3.1.2 get the token list in digest mode
- onvif协议相关:常用类说明
- Onvif protocol related: 4.1.3 WS username token method to obtain screenshot URL
- [code shoe set novice village question 600] for the formatting control of strings, that is, the width and accuracy of strings
- NFT市场格局仍未变化,Okaleido能否掀起新一轮波澜?
- Google Earth Engine——1992—至今混合坐标海洋模型、水温和盐度(全球海洋数据集HYCOM)
- [code hoof set novice village question 600] format specifier of float and double
- 【码蹄集新手村 600 题】针对于字符串的格式化控制,即字符串的宽度与精度
- Helloword and led: a quick start to Hongmeng device development -- Huawei cloud 14 day Hongmeng device development practical learning notes Chapter 2
- AcWing 134. 双端队列
猜你喜欢

Qt之使用QLisView实现QQ登录历史列表

onvif協議相關:4.1.3 WS-Username token方式獲取截圖url
![Codeforce:g. good key, bad key [greed]](/img/5e/e34e549c15e2e495d3a274ea8e6f82.png)
Codeforce:g. good key, bad key [greed]

No.4 bits, bytes, information storage

onvif协议相关:4.1.3 WS-Username token方式获取截图url
![[postgraduate entrance examination vocabulary training camp] day 7 - second, attract, current, collect, simple, communicate, vocation](/img/4e/79da9868930994fe6389b717efc4e9.png)
[postgraduate entrance examination vocabulary training camp] day 7 - second, attract, current, collect, simple, communicate, vocation

565. Array nesting

这些年我开源的几个小项目

NO.6浮点数的表示与运算

【码蹄集新手村 600 题】计算一个整数有多少位数
随机推荐
【7.9】代码源 -【选数】【序列操作】【Minimum Or Spanning Tree】
微服务调用组件feign实战
onvif协议相关:3.1.1 Digest方式获取Authorization
onvif协议相关:3.1.2 Digest方式获取token列表
Perl command batch replaces some contents in the file
Some common operation commands of the command line and solutions to common errors
Onvif protocol related: 4.1.2 WS username token method to obtain token
Programming examples of stm32f1 and stm32subeide -mpu-6050 six axis (gyroscope + accelerometer) drive
洛谷P2422 良好的感觉 题解
onvif协议相关:2.1.3 none方式获取流地址
[postgraduate entrance examination vocabulary training camp] day 5 - alarm, cooperate, point, benefit, industrial, revolution, mechanism
Onvif protocol related: 4.1.3 WS username token method to obtain screenshot URL
chrome插件用于信息收集
【7.13】代码源 -【饿饿 饭饭】【路径计数2】【函数求和】
ModuleNotFoundError: No module named ‘_ distutils_ hack‘
【码蹄集新手村 600 题】输出时的左对齐,右对齐
统计直播间的榜一信息,从这里起步
ModuleNotFoundError: No module named ‘_distutils_hack‘
onvif協議相關:4.1.3 WS-Username token方式獲取截圖url
FreeRTOS-空闲任务和阻塞延时的实现