# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
923836 |
2024-02-08T00:28:01 Z |
AdamGS |
Rope (JOI17_rope) |
C++17 |
|
626 ms |
85700 KB |
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e6+7;
vector<int>V[LIM];
int ile[LIM], ileile[LIM], wynik[LIM], sum, ma;
void dodaj(int x) {
if(x==-1) return;
--ileile[ile[x]];
++ile[x];
++ileile[ile[x]];
ma=max(ma, ile[x]);
++sum;
}
void usun(int x) {
if(x==-1) return;
--ileile[ile[x]];
--ile[x];
++ileile[ile[x]];
if(!ileile[ma]) --ma;
--sum;
}
void solve(vector<pair<int,int>>T, int m) {
sum=ma=0;
rep(i, LIM) {
V[i].clear();
ile[i]=ileile[i]=0;
}
int n=T.size();
rep(i, n) {
V[T[i].st].pb(i);
if(T[i].nd!=-1 && T[i].nd!=T[i].st) V[T[i].nd].pb(i);
dodaj(T[i].st);
dodaj(T[i].nd);
}
rep(i, m) {
int akt=0;
for(auto j : V[i]) {
usun(T[j].st);
usun(T[j].nd);
if(T[j].st!=i) ++akt;
if(T[j].nd!=-1 && T[j].nd!=i) ++akt;
}
wynik[i]=min(wynik[i], akt+sum-ma);
for(auto j : V[i]) {
dodaj(T[j].st);
dodaj(T[j].nd);
}
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m;
cin >> n >> m;
rep(i, m) wynik[i]=n;
vector<int>T(n);
rep(i, n) {
cin >> T[i]; --T[i];
}
vector<pair<int,int>>P;
if(n%2==0) {
rep(i, n/2) P.pb({T[2*i], T[2*i+1]});
solve(P, m);
P.clear();
P.pb({T[0], -1});
rep(i, n/2-1) P.pb({T[2*i+1], T[2*i+2]});
P.pb({T[n-1], -1});
solve(P, m);
} else {
rep(i, n/2) P.pb({T[2*i], T[2*i+1]});
P.pb({T[n-1], -1});
solve(P, m);
P.clear();
P.pb({T[0], -1});
rep(i, n/2) P.pb({T[2*i+1], T[2*i+2]});
solve(P, m);
}
rep(i, m) cout << wynik[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
33372 KB |
Output is correct |
2 |
Correct |
11 ms |
33372 KB |
Output is correct |
3 |
Correct |
11 ms |
33444 KB |
Output is correct |
4 |
Correct |
11 ms |
33624 KB |
Output is correct |
5 |
Correct |
11 ms |
33372 KB |
Output is correct |
6 |
Correct |
10 ms |
33372 KB |
Output is correct |
7 |
Correct |
11 ms |
33368 KB |
Output is correct |
8 |
Correct |
11 ms |
33372 KB |
Output is correct |
9 |
Correct |
11 ms |
33372 KB |
Output is correct |
10 |
Correct |
11 ms |
33224 KB |
Output is correct |
11 |
Correct |
11 ms |
33368 KB |
Output is correct |
12 |
Correct |
11 ms |
33372 KB |
Output is correct |
13 |
Correct |
12 ms |
33452 KB |
Output is correct |
14 |
Correct |
11 ms |
33368 KB |
Output is correct |
15 |
Correct |
11 ms |
33372 KB |
Output is correct |
16 |
Correct |
11 ms |
33372 KB |
Output is correct |
17 |
Correct |
11 ms |
33372 KB |
Output is correct |
18 |
Correct |
11 ms |
33452 KB |
Output is correct |
19 |
Correct |
11 ms |
33368 KB |
Output is correct |
20 |
Correct |
11 ms |
33432 KB |
Output is correct |
21 |
Correct |
13 ms |
33372 KB |
Output is correct |
22 |
Correct |
11 ms |
33372 KB |
Output is correct |
23 |
Correct |
11 ms |
33372 KB |
Output is correct |
24 |
Correct |
11 ms |
33432 KB |
Output is correct |
25 |
Correct |
11 ms |
33372 KB |
Output is correct |
26 |
Correct |
11 ms |
33372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
33372 KB |
Output is correct |
2 |
Correct |
11 ms |
33372 KB |
Output is correct |
3 |
Correct |
11 ms |
33444 KB |
Output is correct |
4 |
Correct |
11 ms |
33624 KB |
Output is correct |
5 |
Correct |
11 ms |
33372 KB |
Output is correct |
6 |
Correct |
10 ms |
33372 KB |
Output is correct |
7 |
Correct |
11 ms |
33368 KB |
Output is correct |
8 |
Correct |
11 ms |
33372 KB |
Output is correct |
9 |
Correct |
11 ms |
33372 KB |
Output is correct |
10 |
Correct |
11 ms |
33224 KB |
Output is correct |
11 |
Correct |
11 ms |
33368 KB |
Output is correct |
12 |
Correct |
11 ms |
33372 KB |
Output is correct |
13 |
Correct |
12 ms |
33452 KB |
Output is correct |
14 |
Correct |
11 ms |
33368 KB |
Output is correct |
15 |
Correct |
11 ms |
33372 KB |
Output is correct |
16 |
Correct |
11 ms |
33372 KB |
Output is correct |
17 |
Correct |
11 ms |
33372 KB |
Output is correct |
18 |
Correct |
11 ms |
33452 KB |
Output is correct |
19 |
Correct |
11 ms |
33368 KB |
Output is correct |
20 |
Correct |
11 ms |
33432 KB |
Output is correct |
21 |
Correct |
13 ms |
33372 KB |
Output is correct |
22 |
Correct |
11 ms |
33372 KB |
Output is correct |
23 |
Correct |
11 ms |
33372 KB |
Output is correct |
24 |
Correct |
11 ms |
33432 KB |
Output is correct |
25 |
Correct |
11 ms |
33372 KB |
Output is correct |
26 |
Correct |
11 ms |
33372 KB |
Output is correct |
27 |
Correct |
20 ms |
35288 KB |
Output is correct |
28 |
Correct |
20 ms |
35136 KB |
Output is correct |
29 |
Correct |
20 ms |
35156 KB |
Output is correct |
30 |
Correct |
21 ms |
35156 KB |
Output is correct |
31 |
Correct |
21 ms |
35156 KB |
Output is correct |
32 |
Correct |
21 ms |
35292 KB |
Output is correct |
33 |
Correct |
21 ms |
35156 KB |
Output is correct |
34 |
Correct |
22 ms |
35152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
33372 KB |
Output is correct |
2 |
Correct |
11 ms |
33372 KB |
Output is correct |
3 |
Correct |
11 ms |
33444 KB |
Output is correct |
4 |
Correct |
11 ms |
33624 KB |
Output is correct |
5 |
Correct |
11 ms |
33372 KB |
Output is correct |
6 |
Correct |
10 ms |
33372 KB |
Output is correct |
7 |
Correct |
11 ms |
33368 KB |
Output is correct |
8 |
Correct |
11 ms |
33372 KB |
Output is correct |
9 |
Correct |
11 ms |
33372 KB |
Output is correct |
10 |
Correct |
11 ms |
33224 KB |
Output is correct |
11 |
Correct |
11 ms |
33368 KB |
Output is correct |
12 |
Correct |
11 ms |
33372 KB |
Output is correct |
13 |
Correct |
12 ms |
33452 KB |
Output is correct |
14 |
Correct |
11 ms |
33368 KB |
Output is correct |
15 |
Correct |
11 ms |
33372 KB |
Output is correct |
16 |
Correct |
11 ms |
33372 KB |
Output is correct |
17 |
Correct |
11 ms |
33372 KB |
Output is correct |
18 |
Correct |
11 ms |
33452 KB |
Output is correct |
19 |
Correct |
11 ms |
33368 KB |
Output is correct |
20 |
Correct |
11 ms |
33432 KB |
Output is correct |
21 |
Correct |
13 ms |
33372 KB |
Output is correct |
22 |
Correct |
11 ms |
33372 KB |
Output is correct |
23 |
Correct |
11 ms |
33372 KB |
Output is correct |
24 |
Correct |
11 ms |
33432 KB |
Output is correct |
25 |
Correct |
11 ms |
33372 KB |
Output is correct |
26 |
Correct |
11 ms |
33372 KB |
Output is correct |
27 |
Correct |
20 ms |
35288 KB |
Output is correct |
28 |
Correct |
20 ms |
35136 KB |
Output is correct |
29 |
Correct |
20 ms |
35156 KB |
Output is correct |
30 |
Correct |
21 ms |
35156 KB |
Output is correct |
31 |
Correct |
21 ms |
35156 KB |
Output is correct |
32 |
Correct |
21 ms |
35292 KB |
Output is correct |
33 |
Correct |
21 ms |
35156 KB |
Output is correct |
34 |
Correct |
22 ms |
35152 KB |
Output is correct |
35 |
Correct |
22 ms |
35156 KB |
Output is correct |
36 |
Correct |
22 ms |
35116 KB |
Output is correct |
37 |
Correct |
24 ms |
35464 KB |
Output is correct |
38 |
Correct |
22 ms |
35156 KB |
Output is correct |
39 |
Correct |
22 ms |
35168 KB |
Output is correct |
40 |
Correct |
22 ms |
35292 KB |
Output is correct |
41 |
Correct |
21 ms |
35288 KB |
Output is correct |
42 |
Correct |
21 ms |
35156 KB |
Output is correct |
43 |
Correct |
21 ms |
35288 KB |
Output is correct |
44 |
Correct |
22 ms |
35292 KB |
Output is correct |
45 |
Correct |
21 ms |
35292 KB |
Output is correct |
46 |
Correct |
27 ms |
35640 KB |
Output is correct |
47 |
Correct |
21 ms |
35292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
33372 KB |
Output is correct |
2 |
Correct |
11 ms |
33372 KB |
Output is correct |
3 |
Correct |
11 ms |
33444 KB |
Output is correct |
4 |
Correct |
11 ms |
33624 KB |
Output is correct |
5 |
Correct |
11 ms |
33372 KB |
Output is correct |
6 |
Correct |
10 ms |
33372 KB |
Output is correct |
7 |
Correct |
11 ms |
33368 KB |
Output is correct |
8 |
Correct |
11 ms |
33372 KB |
Output is correct |
9 |
Correct |
11 ms |
33372 KB |
Output is correct |
10 |
Correct |
11 ms |
33224 KB |
Output is correct |
11 |
Correct |
11 ms |
33368 KB |
Output is correct |
12 |
Correct |
11 ms |
33372 KB |
Output is correct |
13 |
Correct |
12 ms |
33452 KB |
Output is correct |
14 |
Correct |
11 ms |
33368 KB |
Output is correct |
15 |
Correct |
11 ms |
33372 KB |
Output is correct |
16 |
Correct |
11 ms |
33372 KB |
Output is correct |
17 |
Correct |
11 ms |
33372 KB |
Output is correct |
18 |
Correct |
11 ms |
33452 KB |
Output is correct |
19 |
Correct |
11 ms |
33368 KB |
Output is correct |
20 |
Correct |
11 ms |
33432 KB |
Output is correct |
21 |
Correct |
13 ms |
33372 KB |
Output is correct |
22 |
Correct |
11 ms |
33372 KB |
Output is correct |
23 |
Correct |
11 ms |
33372 KB |
Output is correct |
24 |
Correct |
11 ms |
33432 KB |
Output is correct |
25 |
Correct |
11 ms |
33372 KB |
Output is correct |
26 |
Correct |
11 ms |
33372 KB |
Output is correct |
27 |
Correct |
20 ms |
35288 KB |
Output is correct |
28 |
Correct |
20 ms |
35136 KB |
Output is correct |
29 |
Correct |
20 ms |
35156 KB |
Output is correct |
30 |
Correct |
21 ms |
35156 KB |
Output is correct |
31 |
Correct |
21 ms |
35156 KB |
Output is correct |
32 |
Correct |
21 ms |
35292 KB |
Output is correct |
33 |
Correct |
21 ms |
35156 KB |
Output is correct |
34 |
Correct |
22 ms |
35152 KB |
Output is correct |
35 |
Correct |
22 ms |
35156 KB |
Output is correct |
36 |
Correct |
22 ms |
35116 KB |
Output is correct |
37 |
Correct |
24 ms |
35464 KB |
Output is correct |
38 |
Correct |
22 ms |
35156 KB |
Output is correct |
39 |
Correct |
22 ms |
35168 KB |
Output is correct |
40 |
Correct |
22 ms |
35292 KB |
Output is correct |
41 |
Correct |
21 ms |
35288 KB |
Output is correct |
42 |
Correct |
21 ms |
35156 KB |
Output is correct |
43 |
Correct |
21 ms |
35288 KB |
Output is correct |
44 |
Correct |
22 ms |
35292 KB |
Output is correct |
45 |
Correct |
21 ms |
35292 KB |
Output is correct |
46 |
Correct |
27 ms |
35640 KB |
Output is correct |
47 |
Correct |
21 ms |
35292 KB |
Output is correct |
48 |
Correct |
129 ms |
51800 KB |
Output is correct |
49 |
Correct |
128 ms |
51836 KB |
Output is correct |
50 |
Correct |
126 ms |
51820 KB |
Output is correct |
51 |
Correct |
129 ms |
51920 KB |
Output is correct |
52 |
Correct |
117 ms |
50776 KB |
Output is correct |
53 |
Correct |
124 ms |
51064 KB |
Output is correct |
54 |
Correct |
122 ms |
50012 KB |
Output is correct |
55 |
Correct |
122 ms |
49884 KB |
Output is correct |
56 |
Correct |
114 ms |
49524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
33372 KB |
Output is correct |
2 |
Correct |
11 ms |
33372 KB |
Output is correct |
3 |
Correct |
11 ms |
33444 KB |
Output is correct |
4 |
Correct |
11 ms |
33624 KB |
Output is correct |
5 |
Correct |
11 ms |
33372 KB |
Output is correct |
6 |
Correct |
10 ms |
33372 KB |
Output is correct |
7 |
Correct |
11 ms |
33368 KB |
Output is correct |
8 |
Correct |
11 ms |
33372 KB |
Output is correct |
9 |
Correct |
11 ms |
33372 KB |
Output is correct |
10 |
Correct |
11 ms |
33224 KB |
Output is correct |
11 |
Correct |
11 ms |
33368 KB |
Output is correct |
12 |
Correct |
11 ms |
33372 KB |
Output is correct |
13 |
Correct |
12 ms |
33452 KB |
Output is correct |
14 |
Correct |
11 ms |
33368 KB |
Output is correct |
15 |
Correct |
11 ms |
33372 KB |
Output is correct |
16 |
Correct |
11 ms |
33372 KB |
Output is correct |
17 |
Correct |
11 ms |
33372 KB |
Output is correct |
18 |
Correct |
11 ms |
33452 KB |
Output is correct |
19 |
Correct |
11 ms |
33368 KB |
Output is correct |
20 |
Correct |
11 ms |
33432 KB |
Output is correct |
21 |
Correct |
13 ms |
33372 KB |
Output is correct |
22 |
Correct |
11 ms |
33372 KB |
Output is correct |
23 |
Correct |
11 ms |
33372 KB |
Output is correct |
24 |
Correct |
11 ms |
33432 KB |
Output is correct |
25 |
Correct |
11 ms |
33372 KB |
Output is correct |
26 |
Correct |
11 ms |
33372 KB |
Output is correct |
27 |
Correct |
20 ms |
35288 KB |
Output is correct |
28 |
Correct |
20 ms |
35136 KB |
Output is correct |
29 |
Correct |
20 ms |
35156 KB |
Output is correct |
30 |
Correct |
21 ms |
35156 KB |
Output is correct |
31 |
Correct |
21 ms |
35156 KB |
Output is correct |
32 |
Correct |
21 ms |
35292 KB |
Output is correct |
33 |
Correct |
21 ms |
35156 KB |
Output is correct |
34 |
Correct |
22 ms |
35152 KB |
Output is correct |
35 |
Correct |
22 ms |
35156 KB |
Output is correct |
36 |
Correct |
22 ms |
35116 KB |
Output is correct |
37 |
Correct |
24 ms |
35464 KB |
Output is correct |
38 |
Correct |
22 ms |
35156 KB |
Output is correct |
39 |
Correct |
22 ms |
35168 KB |
Output is correct |
40 |
Correct |
22 ms |
35292 KB |
Output is correct |
41 |
Correct |
21 ms |
35288 KB |
Output is correct |
42 |
Correct |
21 ms |
35156 KB |
Output is correct |
43 |
Correct |
21 ms |
35288 KB |
Output is correct |
44 |
Correct |
22 ms |
35292 KB |
Output is correct |
45 |
Correct |
21 ms |
35292 KB |
Output is correct |
46 |
Correct |
27 ms |
35640 KB |
Output is correct |
47 |
Correct |
21 ms |
35292 KB |
Output is correct |
48 |
Correct |
129 ms |
51800 KB |
Output is correct |
49 |
Correct |
128 ms |
51836 KB |
Output is correct |
50 |
Correct |
126 ms |
51820 KB |
Output is correct |
51 |
Correct |
129 ms |
51920 KB |
Output is correct |
52 |
Correct |
117 ms |
50776 KB |
Output is correct |
53 |
Correct |
124 ms |
51064 KB |
Output is correct |
54 |
Correct |
122 ms |
50012 KB |
Output is correct |
55 |
Correct |
122 ms |
49884 KB |
Output is correct |
56 |
Correct |
114 ms |
49524 KB |
Output is correct |
57 |
Correct |
626 ms |
85700 KB |
Output is correct |
58 |
Correct |
474 ms |
76924 KB |
Output is correct |
59 |
Correct |
496 ms |
76852 KB |
Output is correct |
60 |
Correct |
531 ms |
80916 KB |
Output is correct |
61 |
Correct |
519 ms |
80916 KB |
Output is correct |
62 |
Correct |
229 ms |
68412 KB |
Output is correct |
63 |
Correct |
335 ms |
72676 KB |
Output is correct |
64 |
Correct |
265 ms |
70080 KB |
Output is correct |
65 |
Correct |
174 ms |
63144 KB |
Output is correct |