当前位置:网站首页>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
边栏推荐
- NO.2汇编初步
- Importerror: DLL load failed while importing win32api: the specified program cannot be found.
- Start from here by counting the information of the broadcast room
- 谷歌浏览器开发者工具的使用(掌握!)
- STL string find substring
- onvif协议相关:4.1.4 WS-Username token方式获取流地址
- FreeRTOS-空闲任务和阻塞延时的实现
- 弹性负载均衡将访问流量自动分发到多台云服务器,扩展应用系统对外的服务能力,提高应用程序安全性。
- onvif协议相关:2.1.3 none方式获取流地址
- No.3汇编进阶
猜你喜欢

命令行的一些常用操作命令及常见错误的解决办法

Introduction:Multiple DataFrames

No.3汇编进阶

【码蹄集新手村 600 题】运算符 / 在不同的运算顺序中的类型转换
![[code hoof set novice village question 600] format specifier of float and double](/img/19/433f794617f3c3c72732f1a4efe252.png)
[code hoof set novice village question 600] format specifier of float and double

Onvif protocol related: 3.1.2 get the token list in digest mode

「技术播客月」Day 10: Meta Podcast: 聊聊播客这件事
![[code hoof set novice village question 600] formatted input and output, using 0 to replace the completed space](/img/15/5a13501272165e6488e38a98e3c69c.png)
[code hoof set novice village question 600] formatted input and output, using 0 to replace the completed space

Interview records

FreeRTOS implementation of idle tasks and blocking delay
随机推荐
【7.14】代码源 -【拆方块】【XOR Inverse】【连续子序列】【三角果计数】
ONVIF Protocol Related: 4.1.3 WS - username token Method get capture d'écran URL
Acwing game 60
AcWing 134. Double ended queue
【码蹄集新手村 600 题】输出时的左对齐,右对齐
S32K148_ Can drive (bare metal development)
Deep learning from getting started to giving up the 100 day challenge
Importerror: DLL load failed while importing win32api: the specified program cannot be found.
【动态规划】—— 最长上升子序列模型
OpenSSL operation
Forget about postman. Apifox is better
STL string replication comparison
【7.13】代码源 -【饿饿 饭饭】【路径计数2】【函数求和】
TKE跨云联网挂载CFS
【考研词汇训练营】Day 6 —— eventually,state,create,productivity,stimulate
【7.8】Educational Codeforces Round 131 (Rated for Div. 2)
「技术播客月」Day 10: Meta Podcast: 聊聊播客这件事
Principle of voice communication network
onvif协议相关:4.1.1 WS-Username token方式获取WSUsernameTokenBean
云审计服务CTS是一项付费服务,付费项目包括开通追踪器、事件跟踪以及7天内事件的存储和检索等相关费用