Codeforces Round #767 (Div. 2) C. Meximum Array---思维
作者:互联网
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 200010;
int a[N];
int cnt[N],f[N];
int res[N],idx=0;
int main()
{
int T;
cin>>T;
while(T--)
{
int idx=0;
int n;cin>>n;
for(int i=1;i<=n;i++)cin>>a[i],cnt[i]=0,f[i]=0;
cnt[0]=f[0]=0;
for(int i=1;i<=n;i++)cnt[a[i]]++;
int p=0,last=0;
for(int i=1;i<=n;i++)
{
f[a[i]]++;
while(f[p])p++;
if(!cnt[p])
{
res[++idx]=p;
for(int j=last+1;j<=i;j++)f[a[j]]=0,cnt[a[j]]--;
last=i;
p=0;
}
}
cout<<idx<<endl;
for(int i=1;i<=idx;i++)cout<<res[i]<<" ";puts("");
}
}
标签:cnt,idx,int,res,767,Codeforces,---,++,include 来源: https://blog.csdn.net/qq_51282224/article/details/122657978