当前位置:网站首页>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汇编初步
- "Technology podcast month" day 10: meta podcast: talk about Podcasting
- 【7.12】Codeforces Round #806 (Div. 4)
- How to earn money in low-level cities
- 【码蹄集新手村 600 题】计算一个整数有多少位数
- [7.9] code source - [number selection] [sequence operation] [minimum or spanning tree]
- 565. Array nesting
- STM32F1与STM32CubeIDE编程实例-MPU-6050 六轴(陀螺仪 + 加速度计)驱动
- Running node for getting started with eth
- onvif协议相关:4.1.3 WS-Username token方式获取截图url
猜你喜欢
![[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

No.3 advanced assembly

Onvif protocol related: 2.1.2 get screenshot URL in none mode

(附源码)多种机器学习模型(KNN\LR\RF\Ada\Xg\GBDT...)下的降水降尺度中的模型训练

关于数据字典的一些解惑

uniapp 高德地图定位功能

国内外十大erp软件系统排名!

STM32F1与STM32CubeIDE编程实例-MPU-6050 六轴(陀螺仪 + 加速度计)驱动

Onvif protocol related: 4.1.3 WS username token method to obtain screenshot URL

onvif协议相关:3.1.4 Digest方式获取流地址
随机推荐
云审计服务CTS是一项付费服务,付费项目包括开通追踪器、事件跟踪以及7天内事件的存储和检索等相关费用
主流erp系统排名,主流erp系统对比
Health prevention guide 3: health care
【7.12】Codeforces Round #806 (Div. 4)
【考研词汇训练营】Day 5 —— alarmist,cooperate,point,benefit,industrial,revolution,mechanize
【7.8】Educational Codeforces Round 131 (Rated for Div. 2)
Qt之使用QLisView实现QQ登录历史列表
[postgraduate entrance examination vocabulary training camp] day 7 - second, attract, current, collect, simple, communicate, vocation
Some common operation commands of the command line and solutions to common errors
【动态规划】—— 最长上升子序列模型
uniapp 高德地图定位功能
[机缘参悟-46]:鬼谷子-第十谋篇-谋者,智慧之意也
[learn FPGA programming from scratch -53]: high level chapter - FPGA development based on IP core - principle and configuration of PLL PLL IP core (Xilinx)
Codeforce:a. difference operations [mathematical thinking]
ONVIF Protocol Related: 4.1.3 WS - username token Method get capture d'écran URL
Codeforce:g. good key, bad key [greed]
Analyze and hook sshd to hijack password
[7.15] code source - [neat array 2] [ternary cycle] [reverse pair on tree] [sequence of cochlea]
[understanding of opportunity-46]: Guiguzi - Chapter 10 - schemer, meaning of wisdom
【6.15】Codeforces Round #798 (Div. 2)