#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,ssse3,sse3,sse4,popcnt,avx,mmx,abm,tune=native")
#include <bits/stdc++.h>
#define DEBUG 1
using namespace std;
namespace output{
void __(short x){cout<<x;}
void __(unsigned x){cout<<x;}
void __(int x){cout<<x;}
void __(long long x){cout<<x;}
void __(unsigned long long x){cout<<x;}
void __(double x){cout<<x;}
void __(long double x){cout<<x;}
void __(char x){cout<<x;}
void __(const char*x){cout<<x;}
void __(const string&x){cout<<x;}
void __(bool x){cout<<(x?"true":"false");}
template<class S,class T>
void __(const pair<S,T>&x){__(DEBUG?"(":""),__(x.first),__(DEBUG?", ":" "),__(x.second),__(DEBUG?")":"");}
template<class T>
void __(const vector<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
template<class T>
void __(const set<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
template<class T>
void __(const multiset<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
template<class S,class T>
void __(const map<S,T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
void pr(){cout<<"\n";}
template<class S,class... T>
void pr(const S&a,const T&...b){__(a);if(sizeof...(b))__(' ');pr(b...);}
}
using namespace output;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,char> pic;
typedef pair<double,double> pdd;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pb push_back
#define fox(i,x,y) for(int i=(x);i<=(y);i++)
#define foxr(i,x,y) for(int i=(y);i>=(x);i--)
const int MN = 1e6+6;
int N, M, i, j, arr[MN], cnt[MN];
map<int,int> adj[MN][2]; map<int,int> mp;
inline void del(int x){
if(!(--mp[x])) mp.erase(x);
}
int main(){
for(scanf("%d%d",&N,&M),i=1;i<=N;i++){
scanf("%d",&arr[i]);
cnt[arr[i]]++;
}
for(i=1;i+1<=N;i+=2){
if(arr[i]!=arr[i+1]){
adj[arr[i]][0][arr[i+1]]++;
adj[arr[i+1]][0][arr[i]]++;
}
}
for(i=2;i+1<=N;i+=2){
if(arr[i]!=arr[i+1]){
adj[arr[i]][1][arr[i+1]]++;
adj[arr[i+1]][1][arr[i]]++;
}
}
for(i=1;i<=M;i++){
mp[N-cnt[i]]++;
}
if(M==1){
printf("0\n");
return 0;
}
for(i=1;i<=M;i++){
int ans = N;
for(j=0;j<2;j++){
del(N-cnt[i]);
for(auto v : adj[i][j]){
del(N-cnt[v.first]);
mp[N-cnt[v.first]+v.second]++;
}
auto it = mp.begin();
ans = min(ans,it->first-cnt[i]);
for(auto v : adj[i][j]){
del(N-cnt[v.first]+v.second);
mp[N-cnt[v.first]]++;
}
mp[N-cnt[i]]++;
}
printf("%d\n",ans);
}
return 0;
}
Compilation message
rope.cpp: In function 'int main()':
rope.cpp:59:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(scanf("%d%d",&N,&M),i=1;i<=N;i++){
~~~~~~~~~~~~~~~~~~~^~~~
rope.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&arr[i]);
~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
94200 KB |
Output is correct |
2 |
Correct |
57 ms |
94328 KB |
Output is correct |
3 |
Correct |
58 ms |
94328 KB |
Output is correct |
4 |
Correct |
58 ms |
94200 KB |
Output is correct |
5 |
Correct |
56 ms |
94328 KB |
Output is correct |
6 |
Correct |
57 ms |
94328 KB |
Output is correct |
7 |
Correct |
56 ms |
94200 KB |
Output is correct |
8 |
Correct |
57 ms |
94200 KB |
Output is correct |
9 |
Correct |
58 ms |
94200 KB |
Output is correct |
10 |
Correct |
57 ms |
94200 KB |
Output is correct |
11 |
Correct |
56 ms |
94200 KB |
Output is correct |
12 |
Correct |
57 ms |
94204 KB |
Output is correct |
13 |
Correct |
57 ms |
94200 KB |
Output is correct |
14 |
Correct |
56 ms |
94204 KB |
Output is correct |
15 |
Correct |
58 ms |
94200 KB |
Output is correct |
16 |
Correct |
58 ms |
94200 KB |
Output is correct |
17 |
Correct |
56 ms |
94328 KB |
Output is correct |
18 |
Correct |
56 ms |
94328 KB |
Output is correct |
19 |
Correct |
56 ms |
94200 KB |
Output is correct |
20 |
Correct |
57 ms |
94200 KB |
Output is correct |
21 |
Correct |
56 ms |
94204 KB |
Output is correct |
22 |
Correct |
56 ms |
94200 KB |
Output is correct |
23 |
Correct |
55 ms |
94328 KB |
Output is correct |
24 |
Correct |
58 ms |
94328 KB |
Output is correct |
25 |
Correct |
57 ms |
94204 KB |
Output is correct |
26 |
Correct |
57 ms |
94200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
94200 KB |
Output is correct |
2 |
Correct |
57 ms |
94328 KB |
Output is correct |
3 |
Correct |
58 ms |
94328 KB |
Output is correct |
4 |
Correct |
58 ms |
94200 KB |
Output is correct |
5 |
Correct |
56 ms |
94328 KB |
Output is correct |
6 |
Correct |
57 ms |
94328 KB |
Output is correct |
7 |
Correct |
56 ms |
94200 KB |
Output is correct |
8 |
Correct |
57 ms |
94200 KB |
Output is correct |
9 |
Correct |
58 ms |
94200 KB |
Output is correct |
10 |
Correct |
57 ms |
94200 KB |
Output is correct |
11 |
Correct |
56 ms |
94200 KB |
Output is correct |
12 |
Correct |
57 ms |
94204 KB |
Output is correct |
13 |
Correct |
57 ms |
94200 KB |
Output is correct |
14 |
Correct |
56 ms |
94204 KB |
Output is correct |
15 |
Correct |
58 ms |
94200 KB |
Output is correct |
16 |
Correct |
58 ms |
94200 KB |
Output is correct |
17 |
Correct |
56 ms |
94328 KB |
Output is correct |
18 |
Correct |
56 ms |
94328 KB |
Output is correct |
19 |
Correct |
56 ms |
94200 KB |
Output is correct |
20 |
Correct |
57 ms |
94200 KB |
Output is correct |
21 |
Correct |
56 ms |
94204 KB |
Output is correct |
22 |
Correct |
56 ms |
94200 KB |
Output is correct |
23 |
Correct |
55 ms |
94328 KB |
Output is correct |
24 |
Correct |
58 ms |
94328 KB |
Output is correct |
25 |
Correct |
57 ms |
94204 KB |
Output is correct |
26 |
Correct |
57 ms |
94200 KB |
Output is correct |
27 |
Correct |
71 ms |
94840 KB |
Output is correct |
28 |
Correct |
74 ms |
94864 KB |
Output is correct |
29 |
Correct |
72 ms |
94968 KB |
Output is correct |
30 |
Correct |
69 ms |
94840 KB |
Output is correct |
31 |
Correct |
73 ms |
94840 KB |
Output is correct |
32 |
Correct |
67 ms |
94840 KB |
Output is correct |
33 |
Correct |
75 ms |
94840 KB |
Output is correct |
34 |
Correct |
69 ms |
94840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
94200 KB |
Output is correct |
2 |
Correct |
57 ms |
94328 KB |
Output is correct |
3 |
Correct |
58 ms |
94328 KB |
Output is correct |
4 |
Correct |
58 ms |
94200 KB |
Output is correct |
5 |
Correct |
56 ms |
94328 KB |
Output is correct |
6 |
Correct |
57 ms |
94328 KB |
Output is correct |
7 |
Correct |
56 ms |
94200 KB |
Output is correct |
8 |
Correct |
57 ms |
94200 KB |
Output is correct |
9 |
Correct |
58 ms |
94200 KB |
Output is correct |
10 |
Correct |
57 ms |
94200 KB |
Output is correct |
11 |
Correct |
56 ms |
94200 KB |
Output is correct |
12 |
Correct |
57 ms |
94204 KB |
Output is correct |
13 |
Correct |
57 ms |
94200 KB |
Output is correct |
14 |
Correct |
56 ms |
94204 KB |
Output is correct |
15 |
Correct |
58 ms |
94200 KB |
Output is correct |
16 |
Correct |
58 ms |
94200 KB |
Output is correct |
17 |
Correct |
56 ms |
94328 KB |
Output is correct |
18 |
Correct |
56 ms |
94328 KB |
Output is correct |
19 |
Correct |
56 ms |
94200 KB |
Output is correct |
20 |
Correct |
57 ms |
94200 KB |
Output is correct |
21 |
Correct |
56 ms |
94204 KB |
Output is correct |
22 |
Correct |
56 ms |
94200 KB |
Output is correct |
23 |
Correct |
55 ms |
94328 KB |
Output is correct |
24 |
Correct |
58 ms |
94328 KB |
Output is correct |
25 |
Correct |
57 ms |
94204 KB |
Output is correct |
26 |
Correct |
57 ms |
94200 KB |
Output is correct |
27 |
Correct |
71 ms |
94840 KB |
Output is correct |
28 |
Correct |
74 ms |
94864 KB |
Output is correct |
29 |
Correct |
72 ms |
94968 KB |
Output is correct |
30 |
Correct |
69 ms |
94840 KB |
Output is correct |
31 |
Correct |
73 ms |
94840 KB |
Output is correct |
32 |
Correct |
67 ms |
94840 KB |
Output is correct |
33 |
Correct |
75 ms |
94840 KB |
Output is correct |
34 |
Correct |
69 ms |
94840 KB |
Output is correct |
35 |
Correct |
160 ms |
102776 KB |
Output is correct |
36 |
Correct |
171 ms |
102648 KB |
Output is correct |
37 |
Correct |
167 ms |
102776 KB |
Output is correct |
38 |
Correct |
162 ms |
102648 KB |
Output is correct |
39 |
Correct |
162 ms |
102748 KB |
Output is correct |
40 |
Correct |
110 ms |
99064 KB |
Output is correct |
41 |
Correct |
114 ms |
99064 KB |
Output is correct |
42 |
Correct |
100 ms |
98212 KB |
Output is correct |
43 |
Correct |
107 ms |
98040 KB |
Output is correct |
44 |
Correct |
109 ms |
99192 KB |
Output is correct |
45 |
Correct |
112 ms |
99064 KB |
Output is correct |
46 |
Correct |
105 ms |
98320 KB |
Output is correct |
47 |
Correct |
104 ms |
98168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
94200 KB |
Output is correct |
2 |
Correct |
57 ms |
94328 KB |
Output is correct |
3 |
Correct |
58 ms |
94328 KB |
Output is correct |
4 |
Correct |
58 ms |
94200 KB |
Output is correct |
5 |
Correct |
56 ms |
94328 KB |
Output is correct |
6 |
Correct |
57 ms |
94328 KB |
Output is correct |
7 |
Correct |
56 ms |
94200 KB |
Output is correct |
8 |
Correct |
57 ms |
94200 KB |
Output is correct |
9 |
Correct |
58 ms |
94200 KB |
Output is correct |
10 |
Correct |
57 ms |
94200 KB |
Output is correct |
11 |
Correct |
56 ms |
94200 KB |
Output is correct |
12 |
Correct |
57 ms |
94204 KB |
Output is correct |
13 |
Correct |
57 ms |
94200 KB |
Output is correct |
14 |
Correct |
56 ms |
94204 KB |
Output is correct |
15 |
Correct |
58 ms |
94200 KB |
Output is correct |
16 |
Correct |
58 ms |
94200 KB |
Output is correct |
17 |
Correct |
56 ms |
94328 KB |
Output is correct |
18 |
Correct |
56 ms |
94328 KB |
Output is correct |
19 |
Correct |
56 ms |
94200 KB |
Output is correct |
20 |
Correct |
57 ms |
94200 KB |
Output is correct |
21 |
Correct |
56 ms |
94204 KB |
Output is correct |
22 |
Correct |
56 ms |
94200 KB |
Output is correct |
23 |
Correct |
55 ms |
94328 KB |
Output is correct |
24 |
Correct |
58 ms |
94328 KB |
Output is correct |
25 |
Correct |
57 ms |
94204 KB |
Output is correct |
26 |
Correct |
57 ms |
94200 KB |
Output is correct |
27 |
Correct |
71 ms |
94840 KB |
Output is correct |
28 |
Correct |
74 ms |
94864 KB |
Output is correct |
29 |
Correct |
72 ms |
94968 KB |
Output is correct |
30 |
Correct |
69 ms |
94840 KB |
Output is correct |
31 |
Correct |
73 ms |
94840 KB |
Output is correct |
32 |
Correct |
67 ms |
94840 KB |
Output is correct |
33 |
Correct |
75 ms |
94840 KB |
Output is correct |
34 |
Correct |
69 ms |
94840 KB |
Output is correct |
35 |
Correct |
160 ms |
102776 KB |
Output is correct |
36 |
Correct |
171 ms |
102648 KB |
Output is correct |
37 |
Correct |
167 ms |
102776 KB |
Output is correct |
38 |
Correct |
162 ms |
102648 KB |
Output is correct |
39 |
Correct |
162 ms |
102748 KB |
Output is correct |
40 |
Correct |
110 ms |
99064 KB |
Output is correct |
41 |
Correct |
114 ms |
99064 KB |
Output is correct |
42 |
Correct |
100 ms |
98212 KB |
Output is correct |
43 |
Correct |
107 ms |
98040 KB |
Output is correct |
44 |
Correct |
109 ms |
99192 KB |
Output is correct |
45 |
Correct |
112 ms |
99064 KB |
Output is correct |
46 |
Correct |
105 ms |
98320 KB |
Output is correct |
47 |
Correct |
104 ms |
98168 KB |
Output is correct |
48 |
Correct |
2444 ms |
188220 KB |
Output is correct |
49 |
Correct |
2359 ms |
188000 KB |
Output is correct |
50 |
Correct |
2382 ms |
188052 KB |
Output is correct |
51 |
Correct |
2219 ms |
174888 KB |
Output is correct |
52 |
Correct |
1893 ms |
158200 KB |
Output is correct |
53 |
Correct |
961 ms |
146428 KB |
Output is correct |
54 |
Correct |
674 ms |
133880 KB |
Output is correct |
55 |
Correct |
657 ms |
132728 KB |
Output is correct |
56 |
Correct |
590 ms |
127480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
94200 KB |
Output is correct |
2 |
Correct |
57 ms |
94328 KB |
Output is correct |
3 |
Correct |
58 ms |
94328 KB |
Output is correct |
4 |
Correct |
58 ms |
94200 KB |
Output is correct |
5 |
Correct |
56 ms |
94328 KB |
Output is correct |
6 |
Correct |
57 ms |
94328 KB |
Output is correct |
7 |
Correct |
56 ms |
94200 KB |
Output is correct |
8 |
Correct |
57 ms |
94200 KB |
Output is correct |
9 |
Correct |
58 ms |
94200 KB |
Output is correct |
10 |
Correct |
57 ms |
94200 KB |
Output is correct |
11 |
Correct |
56 ms |
94200 KB |
Output is correct |
12 |
Correct |
57 ms |
94204 KB |
Output is correct |
13 |
Correct |
57 ms |
94200 KB |
Output is correct |
14 |
Correct |
56 ms |
94204 KB |
Output is correct |
15 |
Correct |
58 ms |
94200 KB |
Output is correct |
16 |
Correct |
58 ms |
94200 KB |
Output is correct |
17 |
Correct |
56 ms |
94328 KB |
Output is correct |
18 |
Correct |
56 ms |
94328 KB |
Output is correct |
19 |
Correct |
56 ms |
94200 KB |
Output is correct |
20 |
Correct |
57 ms |
94200 KB |
Output is correct |
21 |
Correct |
56 ms |
94204 KB |
Output is correct |
22 |
Correct |
56 ms |
94200 KB |
Output is correct |
23 |
Correct |
55 ms |
94328 KB |
Output is correct |
24 |
Correct |
58 ms |
94328 KB |
Output is correct |
25 |
Correct |
57 ms |
94204 KB |
Output is correct |
26 |
Correct |
57 ms |
94200 KB |
Output is correct |
27 |
Correct |
71 ms |
94840 KB |
Output is correct |
28 |
Correct |
74 ms |
94864 KB |
Output is correct |
29 |
Correct |
72 ms |
94968 KB |
Output is correct |
30 |
Correct |
69 ms |
94840 KB |
Output is correct |
31 |
Correct |
73 ms |
94840 KB |
Output is correct |
32 |
Correct |
67 ms |
94840 KB |
Output is correct |
33 |
Correct |
75 ms |
94840 KB |
Output is correct |
34 |
Correct |
69 ms |
94840 KB |
Output is correct |
35 |
Correct |
160 ms |
102776 KB |
Output is correct |
36 |
Correct |
171 ms |
102648 KB |
Output is correct |
37 |
Correct |
167 ms |
102776 KB |
Output is correct |
38 |
Correct |
162 ms |
102648 KB |
Output is correct |
39 |
Correct |
162 ms |
102748 KB |
Output is correct |
40 |
Correct |
110 ms |
99064 KB |
Output is correct |
41 |
Correct |
114 ms |
99064 KB |
Output is correct |
42 |
Correct |
100 ms |
98212 KB |
Output is correct |
43 |
Correct |
107 ms |
98040 KB |
Output is correct |
44 |
Correct |
109 ms |
99192 KB |
Output is correct |
45 |
Correct |
112 ms |
99064 KB |
Output is correct |
46 |
Correct |
105 ms |
98320 KB |
Output is correct |
47 |
Correct |
104 ms |
98168 KB |
Output is correct |
48 |
Correct |
2444 ms |
188220 KB |
Output is correct |
49 |
Correct |
2359 ms |
188000 KB |
Output is correct |
50 |
Correct |
2382 ms |
188052 KB |
Output is correct |
51 |
Correct |
2219 ms |
174888 KB |
Output is correct |
52 |
Correct |
1893 ms |
158200 KB |
Output is correct |
53 |
Correct |
961 ms |
146428 KB |
Output is correct |
54 |
Correct |
674 ms |
133880 KB |
Output is correct |
55 |
Correct |
657 ms |
132728 KB |
Output is correct |
56 |
Correct |
590 ms |
127480 KB |
Output is correct |
57 |
Correct |
1558 ms |
203640 KB |
Output is correct |
58 |
Correct |
1614 ms |
199456 KB |
Output is correct |
59 |
Correct |
1567 ms |
199264 KB |
Output is correct |
60 |
Correct |
1571 ms |
200316 KB |
Output is correct |
61 |
Correct |
1580 ms |
200316 KB |
Output is correct |
62 |
Correct |
876 ms |
150264 KB |
Output is correct |
63 |
Correct |
1119 ms |
168824 KB |
Output is correct |
64 |
Correct |
1016 ms |
159480 KB |
Output is correct |
65 |
Correct |
744 ms |
136312 KB |
Output is correct |