美好的周末,不美好的zr。
一开题?NOIP 2022?
不对,十分有十一分的不对。
正常9:30开比赛,问我去干嘛了,别问,问就是睡个好觉。
T1
没啥难度,可能比种树难点但不多,单调栈搜极长矩阵即可,剩下的就是组合了。
30min写完暴力和正解,感觉不错,特意检查了下初始化,毕竟这是这题的精髓。\
T2
???!!!
梦回喵了个喵,我也想对出题人喵了个喵。
只能说周末自带debuff,不会!!
后面补题,发现远没有原题难,只能说在原题的恐惧debuff和周末的降智debuff让我根本不想打T2。\
T3
T2想了近40h,直接暴毙,吃饭去了不打了。
T4
都说了吃饭去了,你还想让我写。
T2(补)
仔细想了下,大概有了思路。
首先我们发现每次能取一定是取极长的连续颜色段,那么我们可以将相邻相同颜色分段,每次去靠近中间长度最小且长度大于等于2的一定最优。
但是我们发现这个东西并不好控制一个度,考场的时候想到这就没想了,但是本质上这里最多只有2种选法,我们可以暴力去选,然后后面就是顺下去的了,赛时没怎么打。
接着往下想,我们发现当颜色段个数为奇数时候,我们看正中间的删掉就好了,剩下两边又可以合并成极长颜色段。
难考虑的是颜色段为偶数。
如果想要有解,一定是先操作完了中间的所有数,剩下的两边的是相同的,所以我们可以枚举分割线,将偶数变为两个合法奇数序列即可。
code:
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e6+10;
void read(int &a)
{
int w=1,s=0;
char ch=getchar();
while(ch<'0'||'9'<ch)
{
if(ch=='-') w=-1;
ch=getchar();
}
while('0'<=ch&&ch<='9')
{
s=s*10+ch-'0';
ch=getchar();
}
a=s*w;
}
int n;
int a[N],ans[N],del[N];
int p[N],st[N];
int top,cnt;
void solve()
{
read(n);
for(int i=1;i<=n;i++) read(a[i]),ans[i]=0;
top=cnt=0;
for(int i=1;i<=n;i++)
{
if(a[st[top]]!=a[i]) p[++cnt]=st[top];
st[++top]=i;
if(a[i+1]!=a[st[top]]&&cnt>=2&&p[cnt]-1==p[cnt-1]&&a[st[top]]==a[st[top-1]])
{
int sum=1;
while(a[st[top]]==a[st[top-1]])top--,sum++;
top--,cnt--,ans[i]++;
}
}
int u=0;
while(top)
{
int sum=1,v=st[top];
top--;
while(a[st[top]]==a[st[top+1]]) top--,sum++;
if(sum==1) del[++u]=st[top+1];
else
{
if(u&&a[del[u]]==a[v]) ++ans[del[u]],u--;
else ans[v]++;
}
}
if(u) cout<<"No\n"; //没删完
else
{
cout<<"Yes\n";
int res=n;
for(int i=1;i<=n;i++) res+=ans[i];
top=0;
cout<<res<<"\n";
for(int i=1;i<=n;i++)
{
st[++top]=a[i];
cout<<"1\n";
while(ans[i])
{
ans[i]--;
int sum1=1;
while(top>=2&&st[top]==st[top-1])
{
top--,sum1++;
}
top--;
cout<<"2 "<<sum1<<"\n";
}
}
}
}
signed main()
{
int T;
read(T);
while(T--)
{
solve();
}
}