#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
ll readint(){
ll x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,m,c[1000005],cnt[1000005],res[1000005],ord[1000005];
vector<int> g[1000005];
bool bl[1000005];
void solve(int x){
for(int i=1;i<=m;i++){
cnt[i]=0;
g[i].clear();
ord[i]=i;
bl[i]=false;
}
for(int i=1;i<=n;i++) cnt[c[i]]++;
for(int i=1+x;i+1<=n;i+=2){
if(c[i]==c[i+1]) continue;
g[c[i]].push_back(c[i+1]);
g[c[i+1]].push_back(c[i]);
}
sort(ord+1,ord+m+1,[&](int i,int j){return cnt[i]>cnt[j];});
for(int i=1;i<=m;i++){
for(int j:g[i]) cnt[j]--,bl[j]=true;
bl[i]=true;
int ptr=1;
while(ptr<=m&&bl[ord[ptr]]) ptr++;
int mx=0;
for(int j=1;j<=ptr;j++) if(ord[j]!=i) mx=max(mx,cnt[ord[j]]);
res[i]=min(res[i],n-(cnt[i]+mx));
bl[i]=false;
for(int j:g[i]) cnt[j]++,bl[j]=false;
}
}
int main() {
n=readint(); m=readint();
for(int i=1;i<=n;i++) c[i]=readint();
for(int i=1;i<=m;i++) res[i]=n;
solve(0);
solve(1);
for(int i=1;i<=m;i++) printf("%d\n",res[i]);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
31068 KB |
Output is correct |
2 |
Correct |
8 ms |
31216 KB |
Output is correct |
3 |
Correct |
10 ms |
31068 KB |
Output is correct |
4 |
Correct |
9 ms |
31068 KB |
Output is correct |
5 |
Correct |
9 ms |
31068 KB |
Output is correct |
6 |
Correct |
9 ms |
31068 KB |
Output is correct |
7 |
Correct |
9 ms |
31064 KB |
Output is correct |
8 |
Correct |
9 ms |
31068 KB |
Output is correct |
9 |
Correct |
8 ms |
31196 KB |
Output is correct |
10 |
Correct |
8 ms |
31068 KB |
Output is correct |
11 |
Correct |
8 ms |
31068 KB |
Output is correct |
12 |
Correct |
9 ms |
31064 KB |
Output is correct |
13 |
Correct |
9 ms |
31068 KB |
Output is correct |
14 |
Correct |
9 ms |
31200 KB |
Output is correct |
15 |
Correct |
9 ms |
31064 KB |
Output is correct |
16 |
Correct |
9 ms |
31180 KB |
Output is correct |
17 |
Correct |
8 ms |
31068 KB |
Output is correct |
18 |
Correct |
8 ms |
31208 KB |
Output is correct |
19 |
Correct |
10 ms |
31204 KB |
Output is correct |
20 |
Correct |
10 ms |
31068 KB |
Output is correct |
21 |
Correct |
8 ms |
31068 KB |
Output is correct |
22 |
Correct |
9 ms |
31068 KB |
Output is correct |
23 |
Correct |
8 ms |
31068 KB |
Output is correct |
24 |
Correct |
9 ms |
31068 KB |
Output is correct |
25 |
Correct |
8 ms |
31152 KB |
Output is correct |
26 |
Correct |
9 ms |
31064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
31068 KB |
Output is correct |
2 |
Correct |
8 ms |
31216 KB |
Output is correct |
3 |
Correct |
10 ms |
31068 KB |
Output is correct |
4 |
Correct |
9 ms |
31068 KB |
Output is correct |
5 |
Correct |
9 ms |
31068 KB |
Output is correct |
6 |
Correct |
9 ms |
31068 KB |
Output is correct |
7 |
Correct |
9 ms |
31064 KB |
Output is correct |
8 |
Correct |
9 ms |
31068 KB |
Output is correct |
9 |
Correct |
8 ms |
31196 KB |
Output is correct |
10 |
Correct |
8 ms |
31068 KB |
Output is correct |
11 |
Correct |
8 ms |
31068 KB |
Output is correct |
12 |
Correct |
9 ms |
31064 KB |
Output is correct |
13 |
Correct |
9 ms |
31068 KB |
Output is correct |
14 |
Correct |
9 ms |
31200 KB |
Output is correct |
15 |
Correct |
9 ms |
31064 KB |
Output is correct |
16 |
Correct |
9 ms |
31180 KB |
Output is correct |
17 |
Correct |
8 ms |
31068 KB |
Output is correct |
18 |
Correct |
8 ms |
31208 KB |
Output is correct |
19 |
Correct |
10 ms |
31204 KB |
Output is correct |
20 |
Correct |
10 ms |
31068 KB |
Output is correct |
21 |
Correct |
8 ms |
31068 KB |
Output is correct |
22 |
Correct |
9 ms |
31068 KB |
Output is correct |
23 |
Correct |
8 ms |
31068 KB |
Output is correct |
24 |
Correct |
9 ms |
31068 KB |
Output is correct |
25 |
Correct |
8 ms |
31152 KB |
Output is correct |
26 |
Correct |
9 ms |
31064 KB |
Output is correct |
27 |
Correct |
11 ms |
31832 KB |
Output is correct |
28 |
Correct |
10 ms |
31580 KB |
Output is correct |
29 |
Correct |
11 ms |
31724 KB |
Output is correct |
30 |
Correct |
11 ms |
31580 KB |
Output is correct |
31 |
Correct |
11 ms |
31712 KB |
Output is correct |
32 |
Correct |
11 ms |
31580 KB |
Output is correct |
33 |
Correct |
10 ms |
31580 KB |
Output is correct |
34 |
Correct |
11 ms |
31580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
31068 KB |
Output is correct |
2 |
Correct |
8 ms |
31216 KB |
Output is correct |
3 |
Correct |
10 ms |
31068 KB |
Output is correct |
4 |
Correct |
9 ms |
31068 KB |
Output is correct |
5 |
Correct |
9 ms |
31068 KB |
Output is correct |
6 |
Correct |
9 ms |
31068 KB |
Output is correct |
7 |
Correct |
9 ms |
31064 KB |
Output is correct |
8 |
Correct |
9 ms |
31068 KB |
Output is correct |
9 |
Correct |
8 ms |
31196 KB |
Output is correct |
10 |
Correct |
8 ms |
31068 KB |
Output is correct |
11 |
Correct |
8 ms |
31068 KB |
Output is correct |
12 |
Correct |
9 ms |
31064 KB |
Output is correct |
13 |
Correct |
9 ms |
31068 KB |
Output is correct |
14 |
Correct |
9 ms |
31200 KB |
Output is correct |
15 |
Correct |
9 ms |
31064 KB |
Output is correct |
16 |
Correct |
9 ms |
31180 KB |
Output is correct |
17 |
Correct |
8 ms |
31068 KB |
Output is correct |
18 |
Correct |
8 ms |
31208 KB |
Output is correct |
19 |
Correct |
10 ms |
31204 KB |
Output is correct |
20 |
Correct |
10 ms |
31068 KB |
Output is correct |
21 |
Correct |
8 ms |
31068 KB |
Output is correct |
22 |
Correct |
9 ms |
31068 KB |
Output is correct |
23 |
Correct |
8 ms |
31068 KB |
Output is correct |
24 |
Correct |
9 ms |
31068 KB |
Output is correct |
25 |
Correct |
8 ms |
31152 KB |
Output is correct |
26 |
Correct |
9 ms |
31064 KB |
Output is correct |
27 |
Correct |
11 ms |
31832 KB |
Output is correct |
28 |
Correct |
10 ms |
31580 KB |
Output is correct |
29 |
Correct |
11 ms |
31724 KB |
Output is correct |
30 |
Correct |
11 ms |
31580 KB |
Output is correct |
31 |
Correct |
11 ms |
31712 KB |
Output is correct |
32 |
Correct |
11 ms |
31580 KB |
Output is correct |
33 |
Correct |
10 ms |
31580 KB |
Output is correct |
34 |
Correct |
11 ms |
31580 KB |
Output is correct |
35 |
Correct |
13 ms |
31580 KB |
Output is correct |
36 |
Correct |
11 ms |
31640 KB |
Output is correct |
37 |
Correct |
12 ms |
31580 KB |
Output is correct |
38 |
Correct |
12 ms |
31576 KB |
Output is correct |
39 |
Correct |
13 ms |
31704 KB |
Output is correct |
40 |
Correct |
11 ms |
31836 KB |
Output is correct |
41 |
Correct |
14 ms |
31836 KB |
Output is correct |
42 |
Correct |
12 ms |
31832 KB |
Output is correct |
43 |
Correct |
12 ms |
31832 KB |
Output is correct |
44 |
Correct |
12 ms |
31876 KB |
Output is correct |
45 |
Correct |
12 ms |
31836 KB |
Output is correct |
46 |
Correct |
12 ms |
31720 KB |
Output is correct |
47 |
Correct |
12 ms |
31672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
31068 KB |
Output is correct |
2 |
Correct |
8 ms |
31216 KB |
Output is correct |
3 |
Correct |
10 ms |
31068 KB |
Output is correct |
4 |
Correct |
9 ms |
31068 KB |
Output is correct |
5 |
Correct |
9 ms |
31068 KB |
Output is correct |
6 |
Correct |
9 ms |
31068 KB |
Output is correct |
7 |
Correct |
9 ms |
31064 KB |
Output is correct |
8 |
Correct |
9 ms |
31068 KB |
Output is correct |
9 |
Correct |
8 ms |
31196 KB |
Output is correct |
10 |
Correct |
8 ms |
31068 KB |
Output is correct |
11 |
Correct |
8 ms |
31068 KB |
Output is correct |
12 |
Correct |
9 ms |
31064 KB |
Output is correct |
13 |
Correct |
9 ms |
31068 KB |
Output is correct |
14 |
Correct |
9 ms |
31200 KB |
Output is correct |
15 |
Correct |
9 ms |
31064 KB |
Output is correct |
16 |
Correct |
9 ms |
31180 KB |
Output is correct |
17 |
Correct |
8 ms |
31068 KB |
Output is correct |
18 |
Correct |
8 ms |
31208 KB |
Output is correct |
19 |
Correct |
10 ms |
31204 KB |
Output is correct |
20 |
Correct |
10 ms |
31068 KB |
Output is correct |
21 |
Correct |
8 ms |
31068 KB |
Output is correct |
22 |
Correct |
9 ms |
31068 KB |
Output is correct |
23 |
Correct |
8 ms |
31068 KB |
Output is correct |
24 |
Correct |
9 ms |
31068 KB |
Output is correct |
25 |
Correct |
8 ms |
31152 KB |
Output is correct |
26 |
Correct |
9 ms |
31064 KB |
Output is correct |
27 |
Correct |
11 ms |
31832 KB |
Output is correct |
28 |
Correct |
10 ms |
31580 KB |
Output is correct |
29 |
Correct |
11 ms |
31724 KB |
Output is correct |
30 |
Correct |
11 ms |
31580 KB |
Output is correct |
31 |
Correct |
11 ms |
31712 KB |
Output is correct |
32 |
Correct |
11 ms |
31580 KB |
Output is correct |
33 |
Correct |
10 ms |
31580 KB |
Output is correct |
34 |
Correct |
11 ms |
31580 KB |
Output is correct |
35 |
Correct |
13 ms |
31580 KB |
Output is correct |
36 |
Correct |
11 ms |
31640 KB |
Output is correct |
37 |
Correct |
12 ms |
31580 KB |
Output is correct |
38 |
Correct |
12 ms |
31576 KB |
Output is correct |
39 |
Correct |
13 ms |
31704 KB |
Output is correct |
40 |
Correct |
11 ms |
31836 KB |
Output is correct |
41 |
Correct |
14 ms |
31836 KB |
Output is correct |
42 |
Correct |
12 ms |
31832 KB |
Output is correct |
43 |
Correct |
12 ms |
31832 KB |
Output is correct |
44 |
Correct |
12 ms |
31876 KB |
Output is correct |
45 |
Correct |
12 ms |
31836 KB |
Output is correct |
46 |
Correct |
12 ms |
31720 KB |
Output is correct |
47 |
Correct |
12 ms |
31672 KB |
Output is correct |
48 |
Correct |
46 ms |
40788 KB |
Output is correct |
49 |
Correct |
47 ms |
40784 KB |
Output is correct |
50 |
Correct |
44 ms |
40796 KB |
Output is correct |
51 |
Correct |
51 ms |
40676 KB |
Output is correct |
52 |
Correct |
43 ms |
39840 KB |
Output is correct |
53 |
Correct |
43 ms |
40056 KB |
Output is correct |
54 |
Correct |
41 ms |
39304 KB |
Output is correct |
55 |
Correct |
50 ms |
38736 KB |
Output is correct |
56 |
Correct |
41 ms |
38484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
31068 KB |
Output is correct |
2 |
Correct |
8 ms |
31216 KB |
Output is correct |
3 |
Correct |
10 ms |
31068 KB |
Output is correct |
4 |
Correct |
9 ms |
31068 KB |
Output is correct |
5 |
Correct |
9 ms |
31068 KB |
Output is correct |
6 |
Correct |
9 ms |
31068 KB |
Output is correct |
7 |
Correct |
9 ms |
31064 KB |
Output is correct |
8 |
Correct |
9 ms |
31068 KB |
Output is correct |
9 |
Correct |
8 ms |
31196 KB |
Output is correct |
10 |
Correct |
8 ms |
31068 KB |
Output is correct |
11 |
Correct |
8 ms |
31068 KB |
Output is correct |
12 |
Correct |
9 ms |
31064 KB |
Output is correct |
13 |
Correct |
9 ms |
31068 KB |
Output is correct |
14 |
Correct |
9 ms |
31200 KB |
Output is correct |
15 |
Correct |
9 ms |
31064 KB |
Output is correct |
16 |
Correct |
9 ms |
31180 KB |
Output is correct |
17 |
Correct |
8 ms |
31068 KB |
Output is correct |
18 |
Correct |
8 ms |
31208 KB |
Output is correct |
19 |
Correct |
10 ms |
31204 KB |
Output is correct |
20 |
Correct |
10 ms |
31068 KB |
Output is correct |
21 |
Correct |
8 ms |
31068 KB |
Output is correct |
22 |
Correct |
9 ms |
31068 KB |
Output is correct |
23 |
Correct |
8 ms |
31068 KB |
Output is correct |
24 |
Correct |
9 ms |
31068 KB |
Output is correct |
25 |
Correct |
8 ms |
31152 KB |
Output is correct |
26 |
Correct |
9 ms |
31064 KB |
Output is correct |
27 |
Correct |
11 ms |
31832 KB |
Output is correct |
28 |
Correct |
10 ms |
31580 KB |
Output is correct |
29 |
Correct |
11 ms |
31724 KB |
Output is correct |
30 |
Correct |
11 ms |
31580 KB |
Output is correct |
31 |
Correct |
11 ms |
31712 KB |
Output is correct |
32 |
Correct |
11 ms |
31580 KB |
Output is correct |
33 |
Correct |
10 ms |
31580 KB |
Output is correct |
34 |
Correct |
11 ms |
31580 KB |
Output is correct |
35 |
Correct |
13 ms |
31580 KB |
Output is correct |
36 |
Correct |
11 ms |
31640 KB |
Output is correct |
37 |
Correct |
12 ms |
31580 KB |
Output is correct |
38 |
Correct |
12 ms |
31576 KB |
Output is correct |
39 |
Correct |
13 ms |
31704 KB |
Output is correct |
40 |
Correct |
11 ms |
31836 KB |
Output is correct |
41 |
Correct |
14 ms |
31836 KB |
Output is correct |
42 |
Correct |
12 ms |
31832 KB |
Output is correct |
43 |
Correct |
12 ms |
31832 KB |
Output is correct |
44 |
Correct |
12 ms |
31876 KB |
Output is correct |
45 |
Correct |
12 ms |
31836 KB |
Output is correct |
46 |
Correct |
12 ms |
31720 KB |
Output is correct |
47 |
Correct |
12 ms |
31672 KB |
Output is correct |
48 |
Correct |
46 ms |
40788 KB |
Output is correct |
49 |
Correct |
47 ms |
40784 KB |
Output is correct |
50 |
Correct |
44 ms |
40796 KB |
Output is correct |
51 |
Correct |
51 ms |
40676 KB |
Output is correct |
52 |
Correct |
43 ms |
39840 KB |
Output is correct |
53 |
Correct |
43 ms |
40056 KB |
Output is correct |
54 |
Correct |
41 ms |
39304 KB |
Output is correct |
55 |
Correct |
50 ms |
38736 KB |
Output is correct |
56 |
Correct |
41 ms |
38484 KB |
Output is correct |
57 |
Correct |
620 ms |
78932 KB |
Output is correct |
58 |
Correct |
428 ms |
70476 KB |
Output is correct |
59 |
Correct |
425 ms |
70064 KB |
Output is correct |
60 |
Correct |
500 ms |
74032 KB |
Output is correct |
61 |
Correct |
498 ms |
74176 KB |
Output is correct |
62 |
Correct |
165 ms |
61584 KB |
Output is correct |
63 |
Correct |
303 ms |
65688 KB |
Output is correct |
64 |
Correct |
264 ms |
63212 KB |
Output is correct |
65 |
Correct |
94 ms |
54096 KB |
Output is correct |