# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
539143 |
2022-03-18T13:28:20 Z |
vector |
Rope (JOI17_rope) |
C++17 |
|
2500 ms |
147948 KB |
#include<bits/stdc++.h>
#define SIZE 1000001
using namespace std;
int N,M,A[SIZE],B[SIZE],C[SIZE],D[SIZE],ans[SIZE];
vector<int>v1[SIZE],v2[SIZE];
multiset<pair<int,int> >st;
int main()
{
ios_base::sync_with_stdio(0),cin.tie(0);
cin>>N>>M;
for(int i=1;i<=N;i++){
cin>>A[i];
B[A[i]]++;
}
for(int i=1;i<=M;i++){
st.insert({-B[i],i});
ans[i]=1e9;
}
for(int i=1;i<N;i+=2){
v1[A[i]].push_back(A[i+1]);
v1[A[i+1]].push_back(A[i]);
}
for(int i=1;i<=M;i++){
set<int>u;
C[i]=-B[i];
u.insert(i);
for(int j:v1[i]){
if(u.find(j)==u.end()){
C[j]=-B[j];
u.insert(j);
}
st.erase({C[j],j});
st.insert({++C[j],j});
}
st.erase({C[i],i});
if(!st.empty())ans[i]=min(ans[i],N-B[i]+st.begin()->first);
else ans[i]=0;
st.insert({C[i],i});
for(int j:u){
st.erase({C[j],j});
st.insert({-B[j],j});
}
}
for(int i=2;i<N;i+=2){
v2[A[i]].push_back(A[i+1]);
v2[A[i+1]].push_back(A[i]);
}
for(int i=1;i<=M;i++){
set<int>u;
C[i]=-B[i];
u.insert(i);
for(int j:v2[i]){
if(u.find(j)==u.end()){
C[j]=-B[j];
u.insert(j);
}
st.erase({C[j],j});
st.insert({++C[j],j});
}
st.erase({C[i],i});
if(!st.empty())ans[i]=min(ans[i],N-B[i]+st.begin()->first);
else ans[i]=0;
st.insert({C[i],i});
for(int j:u){
st.erase({C[j],j});
st.insert({-B[j],j});
}
printf("%d\n",ans[i]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47316 KB |
Output is correct |
2 |
Correct |
21 ms |
47316 KB |
Output is correct |
3 |
Correct |
22 ms |
47308 KB |
Output is correct |
4 |
Correct |
23 ms |
47324 KB |
Output is correct |
5 |
Correct |
25 ms |
47220 KB |
Output is correct |
6 |
Correct |
23 ms |
47248 KB |
Output is correct |
7 |
Correct |
23 ms |
47316 KB |
Output is correct |
8 |
Correct |
23 ms |
47248 KB |
Output is correct |
9 |
Correct |
28 ms |
47272 KB |
Output is correct |
10 |
Correct |
27 ms |
47316 KB |
Output is correct |
11 |
Correct |
23 ms |
47204 KB |
Output is correct |
12 |
Correct |
23 ms |
47232 KB |
Output is correct |
13 |
Correct |
22 ms |
47316 KB |
Output is correct |
14 |
Correct |
23 ms |
47200 KB |
Output is correct |
15 |
Correct |
27 ms |
47280 KB |
Output is correct |
16 |
Correct |
28 ms |
47284 KB |
Output is correct |
17 |
Correct |
22 ms |
47316 KB |
Output is correct |
18 |
Correct |
23 ms |
47316 KB |
Output is correct |
19 |
Correct |
28 ms |
47316 KB |
Output is correct |
20 |
Correct |
22 ms |
47316 KB |
Output is correct |
21 |
Correct |
22 ms |
47268 KB |
Output is correct |
22 |
Correct |
22 ms |
47312 KB |
Output is correct |
23 |
Correct |
23 ms |
47316 KB |
Output is correct |
24 |
Correct |
23 ms |
47416 KB |
Output is correct |
25 |
Correct |
23 ms |
47204 KB |
Output is correct |
26 |
Correct |
22 ms |
47316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47316 KB |
Output is correct |
2 |
Correct |
21 ms |
47316 KB |
Output is correct |
3 |
Correct |
22 ms |
47308 KB |
Output is correct |
4 |
Correct |
23 ms |
47324 KB |
Output is correct |
5 |
Correct |
25 ms |
47220 KB |
Output is correct |
6 |
Correct |
23 ms |
47248 KB |
Output is correct |
7 |
Correct |
23 ms |
47316 KB |
Output is correct |
8 |
Correct |
23 ms |
47248 KB |
Output is correct |
9 |
Correct |
28 ms |
47272 KB |
Output is correct |
10 |
Correct |
27 ms |
47316 KB |
Output is correct |
11 |
Correct |
23 ms |
47204 KB |
Output is correct |
12 |
Correct |
23 ms |
47232 KB |
Output is correct |
13 |
Correct |
22 ms |
47316 KB |
Output is correct |
14 |
Correct |
23 ms |
47200 KB |
Output is correct |
15 |
Correct |
27 ms |
47280 KB |
Output is correct |
16 |
Correct |
28 ms |
47284 KB |
Output is correct |
17 |
Correct |
22 ms |
47316 KB |
Output is correct |
18 |
Correct |
23 ms |
47316 KB |
Output is correct |
19 |
Correct |
28 ms |
47316 KB |
Output is correct |
20 |
Correct |
22 ms |
47316 KB |
Output is correct |
21 |
Correct |
22 ms |
47268 KB |
Output is correct |
22 |
Correct |
22 ms |
47312 KB |
Output is correct |
23 |
Correct |
23 ms |
47316 KB |
Output is correct |
24 |
Correct |
23 ms |
47416 KB |
Output is correct |
25 |
Correct |
23 ms |
47204 KB |
Output is correct |
26 |
Correct |
22 ms |
47316 KB |
Output is correct |
27 |
Correct |
64 ms |
48796 KB |
Output is correct |
28 |
Correct |
41 ms |
48788 KB |
Output is correct |
29 |
Correct |
49 ms |
48856 KB |
Output is correct |
30 |
Correct |
42 ms |
48868 KB |
Output is correct |
31 |
Correct |
47 ms |
48916 KB |
Output is correct |
32 |
Correct |
42 ms |
48660 KB |
Output is correct |
33 |
Correct |
45 ms |
48716 KB |
Output is correct |
34 |
Correct |
46 ms |
48848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47316 KB |
Output is correct |
2 |
Correct |
21 ms |
47316 KB |
Output is correct |
3 |
Correct |
22 ms |
47308 KB |
Output is correct |
4 |
Correct |
23 ms |
47324 KB |
Output is correct |
5 |
Correct |
25 ms |
47220 KB |
Output is correct |
6 |
Correct |
23 ms |
47248 KB |
Output is correct |
7 |
Correct |
23 ms |
47316 KB |
Output is correct |
8 |
Correct |
23 ms |
47248 KB |
Output is correct |
9 |
Correct |
28 ms |
47272 KB |
Output is correct |
10 |
Correct |
27 ms |
47316 KB |
Output is correct |
11 |
Correct |
23 ms |
47204 KB |
Output is correct |
12 |
Correct |
23 ms |
47232 KB |
Output is correct |
13 |
Correct |
22 ms |
47316 KB |
Output is correct |
14 |
Correct |
23 ms |
47200 KB |
Output is correct |
15 |
Correct |
27 ms |
47280 KB |
Output is correct |
16 |
Correct |
28 ms |
47284 KB |
Output is correct |
17 |
Correct |
22 ms |
47316 KB |
Output is correct |
18 |
Correct |
23 ms |
47316 KB |
Output is correct |
19 |
Correct |
28 ms |
47316 KB |
Output is correct |
20 |
Correct |
22 ms |
47316 KB |
Output is correct |
21 |
Correct |
22 ms |
47268 KB |
Output is correct |
22 |
Correct |
22 ms |
47312 KB |
Output is correct |
23 |
Correct |
23 ms |
47316 KB |
Output is correct |
24 |
Correct |
23 ms |
47416 KB |
Output is correct |
25 |
Correct |
23 ms |
47204 KB |
Output is correct |
26 |
Correct |
22 ms |
47316 KB |
Output is correct |
27 |
Correct |
64 ms |
48796 KB |
Output is correct |
28 |
Correct |
41 ms |
48788 KB |
Output is correct |
29 |
Correct |
49 ms |
48856 KB |
Output is correct |
30 |
Correct |
42 ms |
48868 KB |
Output is correct |
31 |
Correct |
47 ms |
48916 KB |
Output is correct |
32 |
Correct |
42 ms |
48660 KB |
Output is correct |
33 |
Correct |
45 ms |
48716 KB |
Output is correct |
34 |
Correct |
46 ms |
48848 KB |
Output is correct |
35 |
Correct |
157 ms |
48852 KB |
Output is correct |
36 |
Correct |
137 ms |
48824 KB |
Output is correct |
37 |
Correct |
140 ms |
48716 KB |
Output is correct |
38 |
Correct |
160 ms |
48812 KB |
Output is correct |
39 |
Correct |
137 ms |
48820 KB |
Output is correct |
40 |
Correct |
115 ms |
49028 KB |
Output is correct |
41 |
Correct |
115 ms |
49136 KB |
Output is correct |
42 |
Correct |
105 ms |
48972 KB |
Output is correct |
43 |
Correct |
96 ms |
49028 KB |
Output is correct |
44 |
Correct |
104 ms |
49016 KB |
Output is correct |
45 |
Correct |
120 ms |
49144 KB |
Output is correct |
46 |
Correct |
104 ms |
48964 KB |
Output is correct |
47 |
Correct |
99 ms |
49032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47316 KB |
Output is correct |
2 |
Correct |
21 ms |
47316 KB |
Output is correct |
3 |
Correct |
22 ms |
47308 KB |
Output is correct |
4 |
Correct |
23 ms |
47324 KB |
Output is correct |
5 |
Correct |
25 ms |
47220 KB |
Output is correct |
6 |
Correct |
23 ms |
47248 KB |
Output is correct |
7 |
Correct |
23 ms |
47316 KB |
Output is correct |
8 |
Correct |
23 ms |
47248 KB |
Output is correct |
9 |
Correct |
28 ms |
47272 KB |
Output is correct |
10 |
Correct |
27 ms |
47316 KB |
Output is correct |
11 |
Correct |
23 ms |
47204 KB |
Output is correct |
12 |
Correct |
23 ms |
47232 KB |
Output is correct |
13 |
Correct |
22 ms |
47316 KB |
Output is correct |
14 |
Correct |
23 ms |
47200 KB |
Output is correct |
15 |
Correct |
27 ms |
47280 KB |
Output is correct |
16 |
Correct |
28 ms |
47284 KB |
Output is correct |
17 |
Correct |
22 ms |
47316 KB |
Output is correct |
18 |
Correct |
23 ms |
47316 KB |
Output is correct |
19 |
Correct |
28 ms |
47316 KB |
Output is correct |
20 |
Correct |
22 ms |
47316 KB |
Output is correct |
21 |
Correct |
22 ms |
47268 KB |
Output is correct |
22 |
Correct |
22 ms |
47312 KB |
Output is correct |
23 |
Correct |
23 ms |
47316 KB |
Output is correct |
24 |
Correct |
23 ms |
47416 KB |
Output is correct |
25 |
Correct |
23 ms |
47204 KB |
Output is correct |
26 |
Correct |
22 ms |
47316 KB |
Output is correct |
27 |
Correct |
64 ms |
48796 KB |
Output is correct |
28 |
Correct |
41 ms |
48788 KB |
Output is correct |
29 |
Correct |
49 ms |
48856 KB |
Output is correct |
30 |
Correct |
42 ms |
48868 KB |
Output is correct |
31 |
Correct |
47 ms |
48916 KB |
Output is correct |
32 |
Correct |
42 ms |
48660 KB |
Output is correct |
33 |
Correct |
45 ms |
48716 KB |
Output is correct |
34 |
Correct |
46 ms |
48848 KB |
Output is correct |
35 |
Correct |
157 ms |
48852 KB |
Output is correct |
36 |
Correct |
137 ms |
48824 KB |
Output is correct |
37 |
Correct |
140 ms |
48716 KB |
Output is correct |
38 |
Correct |
160 ms |
48812 KB |
Output is correct |
39 |
Correct |
137 ms |
48820 KB |
Output is correct |
40 |
Correct |
115 ms |
49028 KB |
Output is correct |
41 |
Correct |
115 ms |
49136 KB |
Output is correct |
42 |
Correct |
105 ms |
48972 KB |
Output is correct |
43 |
Correct |
96 ms |
49028 KB |
Output is correct |
44 |
Correct |
104 ms |
49016 KB |
Output is correct |
45 |
Correct |
120 ms |
49144 KB |
Output is correct |
46 |
Correct |
104 ms |
48964 KB |
Output is correct |
47 |
Correct |
99 ms |
49032 KB |
Output is correct |
48 |
Correct |
1574 ms |
64684 KB |
Output is correct |
49 |
Correct |
1541 ms |
69068 KB |
Output is correct |
50 |
Correct |
1557 ms |
69336 KB |
Output is correct |
51 |
Correct |
1390 ms |
68820 KB |
Output is correct |
52 |
Correct |
1261 ms |
66024 KB |
Output is correct |
53 |
Correct |
1109 ms |
67556 KB |
Output is correct |
54 |
Correct |
1022 ms |
65524 KB |
Output is correct |
55 |
Correct |
1000 ms |
65168 KB |
Output is correct |
56 |
Correct |
959 ms |
64608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47316 KB |
Output is correct |
2 |
Correct |
21 ms |
47316 KB |
Output is correct |
3 |
Correct |
22 ms |
47308 KB |
Output is correct |
4 |
Correct |
23 ms |
47324 KB |
Output is correct |
5 |
Correct |
25 ms |
47220 KB |
Output is correct |
6 |
Correct |
23 ms |
47248 KB |
Output is correct |
7 |
Correct |
23 ms |
47316 KB |
Output is correct |
8 |
Correct |
23 ms |
47248 KB |
Output is correct |
9 |
Correct |
28 ms |
47272 KB |
Output is correct |
10 |
Correct |
27 ms |
47316 KB |
Output is correct |
11 |
Correct |
23 ms |
47204 KB |
Output is correct |
12 |
Correct |
23 ms |
47232 KB |
Output is correct |
13 |
Correct |
22 ms |
47316 KB |
Output is correct |
14 |
Correct |
23 ms |
47200 KB |
Output is correct |
15 |
Correct |
27 ms |
47280 KB |
Output is correct |
16 |
Correct |
28 ms |
47284 KB |
Output is correct |
17 |
Correct |
22 ms |
47316 KB |
Output is correct |
18 |
Correct |
23 ms |
47316 KB |
Output is correct |
19 |
Correct |
28 ms |
47316 KB |
Output is correct |
20 |
Correct |
22 ms |
47316 KB |
Output is correct |
21 |
Correct |
22 ms |
47268 KB |
Output is correct |
22 |
Correct |
22 ms |
47312 KB |
Output is correct |
23 |
Correct |
23 ms |
47316 KB |
Output is correct |
24 |
Correct |
23 ms |
47416 KB |
Output is correct |
25 |
Correct |
23 ms |
47204 KB |
Output is correct |
26 |
Correct |
22 ms |
47316 KB |
Output is correct |
27 |
Correct |
64 ms |
48796 KB |
Output is correct |
28 |
Correct |
41 ms |
48788 KB |
Output is correct |
29 |
Correct |
49 ms |
48856 KB |
Output is correct |
30 |
Correct |
42 ms |
48868 KB |
Output is correct |
31 |
Correct |
47 ms |
48916 KB |
Output is correct |
32 |
Correct |
42 ms |
48660 KB |
Output is correct |
33 |
Correct |
45 ms |
48716 KB |
Output is correct |
34 |
Correct |
46 ms |
48848 KB |
Output is correct |
35 |
Correct |
157 ms |
48852 KB |
Output is correct |
36 |
Correct |
137 ms |
48824 KB |
Output is correct |
37 |
Correct |
140 ms |
48716 KB |
Output is correct |
38 |
Correct |
160 ms |
48812 KB |
Output is correct |
39 |
Correct |
137 ms |
48820 KB |
Output is correct |
40 |
Correct |
115 ms |
49028 KB |
Output is correct |
41 |
Correct |
115 ms |
49136 KB |
Output is correct |
42 |
Correct |
105 ms |
48972 KB |
Output is correct |
43 |
Correct |
96 ms |
49028 KB |
Output is correct |
44 |
Correct |
104 ms |
49016 KB |
Output is correct |
45 |
Correct |
120 ms |
49144 KB |
Output is correct |
46 |
Correct |
104 ms |
48964 KB |
Output is correct |
47 |
Correct |
99 ms |
49032 KB |
Output is correct |
48 |
Correct |
1574 ms |
64684 KB |
Output is correct |
49 |
Correct |
1541 ms |
69068 KB |
Output is correct |
50 |
Correct |
1557 ms |
69336 KB |
Output is correct |
51 |
Correct |
1390 ms |
68820 KB |
Output is correct |
52 |
Correct |
1261 ms |
66024 KB |
Output is correct |
53 |
Correct |
1109 ms |
67556 KB |
Output is correct |
54 |
Correct |
1022 ms |
65524 KB |
Output is correct |
55 |
Correct |
1000 ms |
65168 KB |
Output is correct |
56 |
Correct |
959 ms |
64608 KB |
Output is correct |
57 |
Execution timed out |
2552 ms |
147948 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |