Code
#include<bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar_unlocked();
while(c > '9' || c < '0') {
if(c == '-') f = -1;
c = getchar_unlocked();
}
while(c <= '9' && c >= '0') {
x = x * 10 + c - '0';
c = getchar_unlocked();
}
return x * f;
}
int check(int a) {
if(a < 1e1) return 1;
if(a < 1e2) return 2;
if(a < 1e3) return 3;
if(a < 1e4) return 4;
if(a < 1e5) return 5;
if(a < 1e6) return 6;
if(a < 1e7) return 7;
if(a < 1e8) return 8;
}
int main() {
long long n = read(), m = read(), a[500010], siz[500010] = { };
bool fl[500010] = { };
int a2 = read();
siz[a2] = 1;
fl[a2] = true;
for(int i = 2; i <= n; i++) {
int a1 = read();
if(fl[a1]) {
siz[a1] = siz[a2]; continue;
}
siz[a1] = siz[a2] + 1 + check(a1);
a2 = a1;
fl[a2] = true;
}
for(int i = 1; i <= m; i++) {
cout <<siz[i] <<" ";
}
return 0;
}