CF1092D2
我们先来考虑 V1。
V1
给定一个序列
-
若
a_i=a_{i\ +\ 1} ,则可将a_i 与a_{i\ +\ 1} (1\le i < n )同时加1 ; -
将
a_i (1\le i\le n )加2 。
求问是否可经过多此操作后使得所有
首先我们考虑第
下面我们来讨论一些情况。
这种情况我们先把中间两个
一目了然了。
上面是一些具体的例子,下面我们来考虑比较普遍的情况。我们考虑把所有
现在问题看上去貌似简单了一些:给定
于是我们可以想到括号匹配,用栈来维护。我们定义一种括号匹配为 ( 与 ( 匹配,) 与 ) 匹配,那么本题就是询问能否在这种匹配规则下完成匹配,或者只有一个字符无法匹配(思考为什么这种情况也合法)。详情看代码。
V2
我们发现我们不能使用操作
我们再来考虑
我们把 V1 的代码添加这个限制即可。
/*
CB Ntsc
*/
#include<bits/stdc++.h>
using namespace std;
// #define long long long long
#define mp make_pair
#define rd read()
inline long long read()
{
long long xx=0,ff=1;
char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') ff=-1;ch=getchar();}
while(ch>='0'&&ch<='9') xx=xx*10+(ch-'0'),ch=getchar();
return xx*ff;
}
inline void write(long long out)
{
if(out<0) putchar('-'),out=-out;
if(out>9) write(out/10);
putchar(out%10+'0');
}
const long long N=5e5+5;
const long long M=5e5+5;
const long long INF=2e9+5;
const long long MOD=2e9+7;
bool f1;
long long n,t,m;
long long stk[N],top;
long long ans;
bool f2;
int mxlst,lst;
signed main(){
// freopen("woof.in","r",stdin);
// freopen("woof.out","w",stdout);
n=rd;
while(n--){
int a=rd;
if(top&&stk[top]==a&&(a>=lst||m)){
m=0,top--,lst=a;
if(mxlst<a)mxlst=a;
}
else stk[++top]=a,m=1;
}
if(!top||(top==1&&stk[1]>=mxlst))cout<<"YES";
else cout<<"NO";
}
/*
2 5
0 1 1 1 1
0 1 1 2 4
0 2 1 2 1
0 2 1 1 4
*/