# 题意

$n,m\le 100000$$n,m\le100000$

# 分析

$\underset{i=1}{\overset{n}{min}}\left(\underset{j\ge 0}{max}\left({T}_{i+j}+n-j-1\right)\right)$

$\underset{i=1}{\overset{n}{min}}\left(\underset{j\ge 0}{max}\left({p}_{j}\right)+i\right)+n-1$

# 代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

const int N=200005;
const int inf=1000000000;

int n,m,ty,p[N],tim[N];
struct tree{int mx,lef,ans;}t[N*4];

{
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}

int query(int d,int l,int r,int x)
{
if (l==r) return t[d].mx>=x?l:0;
int mid=(l+r)/2;
if (t[d*2+1].mx>=x) return query(d*2+1,mid+1,r,x);
else return query(d*2,l,mid,x);
}

int find(int d,int l,int r,int x)
{
if (l==r) return t[d].mx>=x?t[d].ans:inf;
int mid=(l+r)/2;
if (t[d*2+1].mx>=x) return std::min(t[d].lef,find(d*2+1,mid+1,r,x));
else return find(d*2,l,mid,x);
}

void updata(int d,int l,int r)
{
int mid=(l+r)/2,x=t[d*2+1].mx;
t[d].mx=std::max(t[d*2].mx,t[d*2+1].mx);
int pos=std::max(query(d*2,l,mid,x),l-1);
t[d].lef=std::min(find(d*2,l,mid,x),pos+1+x);
t[d].ans=std::min(t[d].lef,t[d*2+1].ans);
}

void build(int d,int l,int r)
{
if (l==r) {t[d].mx=tim[l]-l;t[d].ans=tim[l];return;}
int mid=(l+r)/2;
build(d*2,l,mid);build(d*2+1,mid+1,r);
updata(d,l,r);
}

void modify(int d,int l,int r,int x)
{
if (l==r) {t[d].mx=tim[l]-l;t[d].ans=tim[l];return;}
int mid=(l+r)/2;
if (x<=mid) modify(d*2,l,mid,x);
else modify(d*2+1,mid+1,r,x);
updata(d,l,r);
}

int main()
{
for (int i=1;i<=n*2;i++) p[i]=tim[i]-i;
build(1,1,n*2);
int ans;
printf("%d\n",ans=t[1].lef+n-1);
while (m--)
{
}