m [500005] : 储存文件名
n [500005] : 储存文件内容
#include<bits/stdc++.h>
using namespace std;
string n[500005];int m[500005],top=1;
//m数组是文件名数组,n数组是文件内容数组
void ls(int s){
//1.检查 m 数组内有没有 s
int f=1,wz;
for(int i=1;i<top;i++){if(m[i]==s){n[i]="";wz=i;f=0;}}
if(f){wz=top;m[top]=s;n[top]="";top++;}//新建
//2.遍历 m 数组,将文件名储存并赋值到对应的 m 数组项
string x="";//文件内容
for(int i=1;i<top;i++){
//转换int为string
int zh=m[i];string nx="";
while(zh){nx+=((zh%10)+'0');zh/=10;}x+=nx;
if(i!=top-1){x+=' ';}
}
n[wz]=x;//赋值
}
int main(){
int a,b;scanf("%d %d",&a,&b);
for(int i=1;i<=a;i++){int s;cin>>s;ls(s);}
int tong[500005];//用一个桶来储存长度
for(int i=1;i<top;i++){tong[m[i]]=n[i].length();}
for(int i=1;i<top;i++){cout<<tong[i]<<' ';}
}