# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1001118 |
2024-06-18T14:55:19 Z |
Otalp |
Rope (JOI17_rope) |
C++14 |
|
779 ms |
159232 KB |
#include<bits/stdc++.h>
using namespace std;
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define h(a, b) (ll)a * 1e7 + b
unordered_map<ll, int> dp[2];
int cnt[1000001];
int a[1000001];
vector<int> d[1000001];
int g[1000001];
bool cmp(int a, int b){
if(cnt[a] == cnt[b]) return a > b;
return cnt[a] > cnt[b];
}
//ll h(ll a, ll b){ //hynya
// return a * 1e7 + b;
//}
void solve(){
int n, m;
cin>>n>>m;
for(int i=1; i<=n; i++){
cin>>a[i];
cnt[a[i]] ++;
}
for(int i=1; i<=m; i++){
g[i] = i;
}
sort(g + 1, g + 1 + m, cmp);
for(int i=1; i+1<=n; i+=2){
int l=a[i], r=a[i + 1];
if(dp[1].count(h(l, r))){
d[l].pb(r);
d[r].pb(l);
}
dp[1][h(l, r)] ++;
dp[1][h(r, l)] ++;
}
for(int i=2; i+1<=n; i+=2){
int l=a[i], r=a[i + 1];
if(dp[1].count(h(l, r)) or dp[0].count(h(l, r))){
d[l].pb(r);
d[r].pb(l);
}
dp[0][h(l, r)] ++;
dp[0][h(r, l)] ++;
}
ll dd = 0;
for(int i=1; i<=m; i++) dd += d[i].size();
if(dd > 2e6) return;
if(dp[0].size() + dp[1].size() > 2e6) return;
for(int i=1; i<=m; i++){
d[i].pb(i);
sort(d[i].begin(), d[i].end(), cmp);
}
for(int i=1; i<=m; i++){
int ans = n - cnt[i];
int ls = 1;
for(int j: d[i]){
while(ls <= m and g[ls] == j) ls++;
if(j == i) continue;
for(int k=0; k<2; k++){
ans = min(ans, n-cnt[i]-cnt[j]+dp[k][h(i, j)]);
}
}
if(ls <= m) ans = min(ans, n-cnt[i]-cnt[g[ls]]);
cout<<ans<<'\n';
}
}
signed main(){
ios_base::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
solve();
}
Compilation message
rope.cpp:3: warning: ignoring '#pragma optimization_level ' [-Wunknown-pragmas]
3 | #pragma optimization_level 3
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
29020 KB |
Output is correct |
2 |
Correct |
5 ms |
29132 KB |
Output is correct |
3 |
Correct |
5 ms |
29020 KB |
Output is correct |
4 |
Correct |
4 ms |
29020 KB |
Output is correct |
5 |
Correct |
4 ms |
29020 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
29020 KB |
Output is correct |
8 |
Correct |
6 ms |
29124 KB |
Output is correct |
9 |
Correct |
4 ms |
29152 KB |
Output is correct |
10 |
Correct |
4 ms |
29020 KB |
Output is correct |
11 |
Correct |
4 ms |
29020 KB |
Output is correct |
12 |
Correct |
4 ms |
29020 KB |
Output is correct |
13 |
Correct |
4 ms |
29016 KB |
Output is correct |
14 |
Correct |
4 ms |
29020 KB |
Output is correct |
15 |
Correct |
4 ms |
29020 KB |
Output is correct |
16 |
Correct |
5 ms |
29184 KB |
Output is correct |
17 |
Correct |
6 ms |
29020 KB |
Output is correct |
18 |
Correct |
4 ms |
29020 KB |
Output is correct |
19 |
Correct |
4 ms |
29020 KB |
Output is correct |
20 |
Correct |
5 ms |
29128 KB |
Output is correct |
21 |
Correct |
4 ms |
29020 KB |
Output is correct |
22 |
Correct |
6 ms |
29020 KB |
Output is correct |
23 |
Correct |
4 ms |
29020 KB |
Output is correct |
24 |
Correct |
5 ms |
29016 KB |
Output is correct |
25 |
Correct |
4 ms |
29020 KB |
Output is correct |
26 |
Correct |
5 ms |
29020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
29020 KB |
Output is correct |
2 |
Correct |
5 ms |
29132 KB |
Output is correct |
3 |
Correct |
5 ms |
29020 KB |
Output is correct |
4 |
Correct |
4 ms |
29020 KB |
Output is correct |
5 |
Correct |
4 ms |
29020 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
29020 KB |
Output is correct |
8 |
Correct |
6 ms |
29124 KB |
Output is correct |
9 |
Correct |
4 ms |
29152 KB |
Output is correct |
10 |
Correct |
4 ms |
29020 KB |
Output is correct |
11 |
Correct |
4 ms |
29020 KB |
Output is correct |
12 |
Correct |
4 ms |
29020 KB |
Output is correct |
13 |
Correct |
4 ms |
29016 KB |
Output is correct |
14 |
Correct |
4 ms |
29020 KB |
Output is correct |
15 |
Correct |
4 ms |
29020 KB |
Output is correct |
16 |
Correct |
5 ms |
29184 KB |
Output is correct |
17 |
Correct |
6 ms |
29020 KB |
Output is correct |
18 |
Correct |
4 ms |
29020 KB |
Output is correct |
19 |
Correct |
4 ms |
29020 KB |
Output is correct |
20 |
Correct |
5 ms |
29128 KB |
Output is correct |
21 |
Correct |
4 ms |
29020 KB |
Output is correct |
22 |
Correct |
6 ms |
29020 KB |
Output is correct |
23 |
Correct |
4 ms |
29020 KB |
Output is correct |
24 |
Correct |
5 ms |
29016 KB |
Output is correct |
25 |
Correct |
4 ms |
29020 KB |
Output is correct |
26 |
Correct |
5 ms |
29020 KB |
Output is correct |
27 |
Correct |
26 ms |
30296 KB |
Output is correct |
28 |
Correct |
20 ms |
30208 KB |
Output is correct |
29 |
Correct |
25 ms |
30424 KB |
Output is correct |
30 |
Correct |
23 ms |
30160 KB |
Output is correct |
31 |
Correct |
24 ms |
30476 KB |
Output is correct |
32 |
Correct |
22 ms |
30040 KB |
Output is correct |
33 |
Correct |
25 ms |
30300 KB |
Output is correct |
34 |
Correct |
24 ms |
30268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
29020 KB |
Output is correct |
2 |
Correct |
5 ms |
29132 KB |
Output is correct |
3 |
Correct |
5 ms |
29020 KB |
Output is correct |
4 |
Correct |
4 ms |
29020 KB |
Output is correct |
5 |
Correct |
4 ms |
29020 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
29020 KB |
Output is correct |
8 |
Correct |
6 ms |
29124 KB |
Output is correct |
9 |
Correct |
4 ms |
29152 KB |
Output is correct |
10 |
Correct |
4 ms |
29020 KB |
Output is correct |
11 |
Correct |
4 ms |
29020 KB |
Output is correct |
12 |
Correct |
4 ms |
29020 KB |
Output is correct |
13 |
Correct |
4 ms |
29016 KB |
Output is correct |
14 |
Correct |
4 ms |
29020 KB |
Output is correct |
15 |
Correct |
4 ms |
29020 KB |
Output is correct |
16 |
Correct |
5 ms |
29184 KB |
Output is correct |
17 |
Correct |
6 ms |
29020 KB |
Output is correct |
18 |
Correct |
4 ms |
29020 KB |
Output is correct |
19 |
Correct |
4 ms |
29020 KB |
Output is correct |
20 |
Correct |
5 ms |
29128 KB |
Output is correct |
21 |
Correct |
4 ms |
29020 KB |
Output is correct |
22 |
Correct |
6 ms |
29020 KB |
Output is correct |
23 |
Correct |
4 ms |
29020 KB |
Output is correct |
24 |
Correct |
5 ms |
29016 KB |
Output is correct |
25 |
Correct |
4 ms |
29020 KB |
Output is correct |
26 |
Correct |
5 ms |
29020 KB |
Output is correct |
27 |
Correct |
26 ms |
30296 KB |
Output is correct |
28 |
Correct |
20 ms |
30208 KB |
Output is correct |
29 |
Correct |
25 ms |
30424 KB |
Output is correct |
30 |
Correct |
23 ms |
30160 KB |
Output is correct |
31 |
Correct |
24 ms |
30476 KB |
Output is correct |
32 |
Correct |
22 ms |
30040 KB |
Output is correct |
33 |
Correct |
25 ms |
30300 KB |
Output is correct |
34 |
Correct |
24 ms |
30268 KB |
Output is correct |
35 |
Correct |
48 ms |
38092 KB |
Output is correct |
36 |
Correct |
45 ms |
38260 KB |
Output is correct |
37 |
Correct |
40 ms |
38344 KB |
Output is correct |
38 |
Correct |
42 ms |
38080 KB |
Output is correct |
39 |
Correct |
43 ms |
38084 KB |
Output is correct |
40 |
Correct |
32 ms |
34408 KB |
Output is correct |
41 |
Correct |
32 ms |
34412 KB |
Output is correct |
42 |
Correct |
30 ms |
32952 KB |
Output is correct |
43 |
Correct |
32 ms |
32952 KB |
Output is correct |
44 |
Correct |
32 ms |
34412 KB |
Output is correct |
45 |
Correct |
32 ms |
34408 KB |
Output is correct |
46 |
Correct |
31 ms |
32952 KB |
Output is correct |
47 |
Correct |
33 ms |
33112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
29020 KB |
Output is correct |
2 |
Correct |
5 ms |
29132 KB |
Output is correct |
3 |
Correct |
5 ms |
29020 KB |
Output is correct |
4 |
Correct |
4 ms |
29020 KB |
Output is correct |
5 |
Correct |
4 ms |
29020 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
29020 KB |
Output is correct |
8 |
Correct |
6 ms |
29124 KB |
Output is correct |
9 |
Correct |
4 ms |
29152 KB |
Output is correct |
10 |
Correct |
4 ms |
29020 KB |
Output is correct |
11 |
Correct |
4 ms |
29020 KB |
Output is correct |
12 |
Correct |
4 ms |
29020 KB |
Output is correct |
13 |
Correct |
4 ms |
29016 KB |
Output is correct |
14 |
Correct |
4 ms |
29020 KB |
Output is correct |
15 |
Correct |
4 ms |
29020 KB |
Output is correct |
16 |
Correct |
5 ms |
29184 KB |
Output is correct |
17 |
Correct |
6 ms |
29020 KB |
Output is correct |
18 |
Correct |
4 ms |
29020 KB |
Output is correct |
19 |
Correct |
4 ms |
29020 KB |
Output is correct |
20 |
Correct |
5 ms |
29128 KB |
Output is correct |
21 |
Correct |
4 ms |
29020 KB |
Output is correct |
22 |
Correct |
6 ms |
29020 KB |
Output is correct |
23 |
Correct |
4 ms |
29020 KB |
Output is correct |
24 |
Correct |
5 ms |
29016 KB |
Output is correct |
25 |
Correct |
4 ms |
29020 KB |
Output is correct |
26 |
Correct |
5 ms |
29020 KB |
Output is correct |
27 |
Correct |
26 ms |
30296 KB |
Output is correct |
28 |
Correct |
20 ms |
30208 KB |
Output is correct |
29 |
Correct |
25 ms |
30424 KB |
Output is correct |
30 |
Correct |
23 ms |
30160 KB |
Output is correct |
31 |
Correct |
24 ms |
30476 KB |
Output is correct |
32 |
Correct |
22 ms |
30040 KB |
Output is correct |
33 |
Correct |
25 ms |
30300 KB |
Output is correct |
34 |
Correct |
24 ms |
30268 KB |
Output is correct |
35 |
Correct |
48 ms |
38092 KB |
Output is correct |
36 |
Correct |
45 ms |
38260 KB |
Output is correct |
37 |
Correct |
40 ms |
38344 KB |
Output is correct |
38 |
Correct |
42 ms |
38080 KB |
Output is correct |
39 |
Correct |
43 ms |
38084 KB |
Output is correct |
40 |
Correct |
32 ms |
34408 KB |
Output is correct |
41 |
Correct |
32 ms |
34412 KB |
Output is correct |
42 |
Correct |
30 ms |
32952 KB |
Output is correct |
43 |
Correct |
32 ms |
32952 KB |
Output is correct |
44 |
Correct |
32 ms |
34412 KB |
Output is correct |
45 |
Correct |
32 ms |
34408 KB |
Output is correct |
46 |
Correct |
31 ms |
32952 KB |
Output is correct |
47 |
Correct |
33 ms |
33112 KB |
Output is correct |
48 |
Correct |
640 ms |
117308 KB |
Output is correct |
49 |
Correct |
671 ms |
117492 KB |
Output is correct |
50 |
Correct |
709 ms |
117400 KB |
Output is correct |
51 |
Correct |
672 ms |
114160 KB |
Output is correct |
52 |
Correct |
668 ms |
112020 KB |
Output is correct |
53 |
Correct |
443 ms |
81008 KB |
Output is correct |
54 |
Correct |
393 ms |
75196 KB |
Output is correct |
55 |
Correct |
444 ms |
74856 KB |
Output is correct |
56 |
Correct |
380 ms |
63348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
29020 KB |
Output is correct |
2 |
Correct |
5 ms |
29132 KB |
Output is correct |
3 |
Correct |
5 ms |
29020 KB |
Output is correct |
4 |
Correct |
4 ms |
29020 KB |
Output is correct |
5 |
Correct |
4 ms |
29020 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
29020 KB |
Output is correct |
8 |
Correct |
6 ms |
29124 KB |
Output is correct |
9 |
Correct |
4 ms |
29152 KB |
Output is correct |
10 |
Correct |
4 ms |
29020 KB |
Output is correct |
11 |
Correct |
4 ms |
29020 KB |
Output is correct |
12 |
Correct |
4 ms |
29020 KB |
Output is correct |
13 |
Correct |
4 ms |
29016 KB |
Output is correct |
14 |
Correct |
4 ms |
29020 KB |
Output is correct |
15 |
Correct |
4 ms |
29020 KB |
Output is correct |
16 |
Correct |
5 ms |
29184 KB |
Output is correct |
17 |
Correct |
6 ms |
29020 KB |
Output is correct |
18 |
Correct |
4 ms |
29020 KB |
Output is correct |
19 |
Correct |
4 ms |
29020 KB |
Output is correct |
20 |
Correct |
5 ms |
29128 KB |
Output is correct |
21 |
Correct |
4 ms |
29020 KB |
Output is correct |
22 |
Correct |
6 ms |
29020 KB |
Output is correct |
23 |
Correct |
4 ms |
29020 KB |
Output is correct |
24 |
Correct |
5 ms |
29016 KB |
Output is correct |
25 |
Correct |
4 ms |
29020 KB |
Output is correct |
26 |
Correct |
5 ms |
29020 KB |
Output is correct |
27 |
Correct |
26 ms |
30296 KB |
Output is correct |
28 |
Correct |
20 ms |
30208 KB |
Output is correct |
29 |
Correct |
25 ms |
30424 KB |
Output is correct |
30 |
Correct |
23 ms |
30160 KB |
Output is correct |
31 |
Correct |
24 ms |
30476 KB |
Output is correct |
32 |
Correct |
22 ms |
30040 KB |
Output is correct |
33 |
Correct |
25 ms |
30300 KB |
Output is correct |
34 |
Correct |
24 ms |
30268 KB |
Output is correct |
35 |
Correct |
48 ms |
38092 KB |
Output is correct |
36 |
Correct |
45 ms |
38260 KB |
Output is correct |
37 |
Correct |
40 ms |
38344 KB |
Output is correct |
38 |
Correct |
42 ms |
38080 KB |
Output is correct |
39 |
Correct |
43 ms |
38084 KB |
Output is correct |
40 |
Correct |
32 ms |
34408 KB |
Output is correct |
41 |
Correct |
32 ms |
34412 KB |
Output is correct |
42 |
Correct |
30 ms |
32952 KB |
Output is correct |
43 |
Correct |
32 ms |
32952 KB |
Output is correct |
44 |
Correct |
32 ms |
34412 KB |
Output is correct |
45 |
Correct |
32 ms |
34408 KB |
Output is correct |
46 |
Correct |
31 ms |
32952 KB |
Output is correct |
47 |
Correct |
33 ms |
33112 KB |
Output is correct |
48 |
Correct |
640 ms |
117308 KB |
Output is correct |
49 |
Correct |
671 ms |
117492 KB |
Output is correct |
50 |
Correct |
709 ms |
117400 KB |
Output is correct |
51 |
Correct |
672 ms |
114160 KB |
Output is correct |
52 |
Correct |
668 ms |
112020 KB |
Output is correct |
53 |
Correct |
443 ms |
81008 KB |
Output is correct |
54 |
Correct |
393 ms |
75196 KB |
Output is correct |
55 |
Correct |
444 ms |
74856 KB |
Output is correct |
56 |
Correct |
380 ms |
63348 KB |
Output is correct |
57 |
Correct |
779 ms |
159232 KB |
Output is correct |
58 |
Correct |
754 ms |
150284 KB |
Output is correct |
59 |
Correct |
745 ms |
150164 KB |
Output is correct |
60 |
Correct |
753 ms |
154392 KB |
Output is correct |
61 |
Correct |
734 ms |
154364 KB |
Output is correct |
62 |
Correct |
508 ms |
101048 KB |
Output is correct |
63 |
Correct |
545 ms |
115416 KB |
Output is correct |
64 |
Correct |
569 ms |
107660 KB |
Output is correct |
65 |
Correct |
473 ms |
87996 KB |
Output is correct |