# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1051832 |
2024-08-10T10:04:43 Z |
SamAnd |
Rope (JOI17_rope) |
C++17 |
|
427 ms |
83576 KB |
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 1000006;
int nn;
int n, m;
int c[N];
pair<int, int> a[N];
int ans[N];
vector<int> v[N];
int q[N];
int qq[N];
int maxu;
void ubd(int i, int y)
{
if (a[i].fi)
qq[q[a[i].fi]]--;
if (a[i].se && a[i].se != a[i].fi)
qq[q[a[i].se]]--;
q[a[i].fi] += y;
q[a[i].se] += y;
if (a[i].fi)
qq[q[a[i].fi]]++;
if (a[i].se && a[i].se != a[i].fi)
qq[q[a[i].se]]++;
while (1)
{
if (qq[maxu + 1])
++maxu;
else if (qq[maxu + 2])
maxu += 2;
else
break;
}
while (!qq[maxu])
--maxu;
}
void solvv()
{
for (int x = 1; x <= m; ++x)
v[x].clear();
memset(q, 0, sizeof q);
memset(qq, 0, sizeof qq);
maxu = 0;
for (int i = 1; i <= n; ++i)
{
v[a[i].fi].push_back(i);
if (a[i].se != a[i].fi)
v[a[i].se].push_back(i);
}
qq[0] = m;
for (int i = 1; i <= n; ++i)
ubd(i, 1);
for (int x = 1; x <= m; ++x)
{
int yans = 0;
for (int i = 0; i < sz(v[x]); ++i)
{
int j = v[x][i];
ubd(j, -1);
if (a[j].fi == x)
++yans;
if (a[j].se == x)
++yans;
}
yans += maxu;
ans[x] = min(ans[x], nn - yans);
for (int i = 0; i < sz(v[x]); ++i)
{
int j = v[x][i];
ubd(j, 1);
}
}
}
void solv()
{
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> c[i];
nn = n;
for (int i = 1; i <= m; ++i)
ans[i] = n;
if (n % 2 == 0)
{
for (int i = 1; i <= n; i += 2)
{
a[i / 2 + 1] = m_p(c[i], c[i + 1]);
}
n = n / 2;
solvv();
n *= 2;
a[1] = m_p(c[1], 0);
a[2] = m_p(c[n], 0);
for (int i = 2; i < n; i += 2)
{
a[i / 2 + 2] = m_p(c[i], c[i + 1]);
}
n = 2 + (n - 2) / 2;
solvv();
}
else
{
a[1] = m_p(c[1], 0);
for (int i = 2; i <= n; i += 2)
a[i / 2 + 1] = m_p(c[i], c[i + 1]);
n = (n - 1) / 2 + 1;
solvv();
n = (n - 1) * 2 + 1;
a[1] = m_p(c[n], 0);
for (int i = 1; i < n; i += 2)
a[i / 2 + 2] = m_p(c[i], c[i + 1]);
solvv();
}
for (int i = 1; i <= m; ++i)
cout << ans[i] << "\n";
}
int main()
{
#ifdef SOMETHING
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif // SOMETHING
ios_base::sync_with_stdio(false), cin.tie(0);
int tt = 1;
//cin >> tt;
while (tt--)
{
solv();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
37468 KB |
Output is correct |
2 |
Correct |
5 ms |
37468 KB |
Output is correct |
3 |
Correct |
5 ms |
37468 KB |
Output is correct |
4 |
Correct |
5 ms |
37468 KB |
Output is correct |
5 |
Correct |
5 ms |
37464 KB |
Output is correct |
6 |
Correct |
5 ms |
37468 KB |
Output is correct |
7 |
Correct |
4 ms |
37468 KB |
Output is correct |
8 |
Correct |
6 ms |
37468 KB |
Output is correct |
9 |
Correct |
6 ms |
37468 KB |
Output is correct |
10 |
Correct |
5 ms |
37468 KB |
Output is correct |
11 |
Correct |
4 ms |
37468 KB |
Output is correct |
12 |
Correct |
5 ms |
37468 KB |
Output is correct |
13 |
Correct |
5 ms |
37468 KB |
Output is correct |
14 |
Correct |
5 ms |
37468 KB |
Output is correct |
15 |
Correct |
7 ms |
37356 KB |
Output is correct |
16 |
Correct |
5 ms |
37468 KB |
Output is correct |
17 |
Correct |
6 ms |
37468 KB |
Output is correct |
18 |
Correct |
5 ms |
37468 KB |
Output is correct |
19 |
Correct |
6 ms |
37468 KB |
Output is correct |
20 |
Correct |
6 ms |
37468 KB |
Output is correct |
21 |
Correct |
5 ms |
37584 KB |
Output is correct |
22 |
Correct |
5 ms |
37468 KB |
Output is correct |
23 |
Correct |
5 ms |
37392 KB |
Output is correct |
24 |
Correct |
6 ms |
37468 KB |
Output is correct |
25 |
Correct |
4 ms |
37468 KB |
Output is correct |
26 |
Correct |
5 ms |
37468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
37468 KB |
Output is correct |
2 |
Correct |
5 ms |
37468 KB |
Output is correct |
3 |
Correct |
5 ms |
37468 KB |
Output is correct |
4 |
Correct |
5 ms |
37468 KB |
Output is correct |
5 |
Correct |
5 ms |
37464 KB |
Output is correct |
6 |
Correct |
5 ms |
37468 KB |
Output is correct |
7 |
Correct |
4 ms |
37468 KB |
Output is correct |
8 |
Correct |
6 ms |
37468 KB |
Output is correct |
9 |
Correct |
6 ms |
37468 KB |
Output is correct |
10 |
Correct |
5 ms |
37468 KB |
Output is correct |
11 |
Correct |
4 ms |
37468 KB |
Output is correct |
12 |
Correct |
5 ms |
37468 KB |
Output is correct |
13 |
Correct |
5 ms |
37468 KB |
Output is correct |
14 |
Correct |
5 ms |
37468 KB |
Output is correct |
15 |
Correct |
7 ms |
37356 KB |
Output is correct |
16 |
Correct |
5 ms |
37468 KB |
Output is correct |
17 |
Correct |
6 ms |
37468 KB |
Output is correct |
18 |
Correct |
5 ms |
37468 KB |
Output is correct |
19 |
Correct |
6 ms |
37468 KB |
Output is correct |
20 |
Correct |
6 ms |
37468 KB |
Output is correct |
21 |
Correct |
5 ms |
37584 KB |
Output is correct |
22 |
Correct |
5 ms |
37468 KB |
Output is correct |
23 |
Correct |
5 ms |
37392 KB |
Output is correct |
24 |
Correct |
6 ms |
37468 KB |
Output is correct |
25 |
Correct |
4 ms |
37468 KB |
Output is correct |
26 |
Correct |
5 ms |
37468 KB |
Output is correct |
27 |
Correct |
18 ms |
40028 KB |
Output is correct |
28 |
Correct |
15 ms |
40108 KB |
Output is correct |
29 |
Correct |
15 ms |
40540 KB |
Output is correct |
30 |
Correct |
14 ms |
40516 KB |
Output is correct |
31 |
Correct |
12 ms |
40028 KB |
Output is correct |
32 |
Correct |
14 ms |
40304 KB |
Output is correct |
33 |
Correct |
15 ms |
40572 KB |
Output is correct |
34 |
Correct |
13 ms |
40448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
37468 KB |
Output is correct |
2 |
Correct |
5 ms |
37468 KB |
Output is correct |
3 |
Correct |
5 ms |
37468 KB |
Output is correct |
4 |
Correct |
5 ms |
37468 KB |
Output is correct |
5 |
Correct |
5 ms |
37464 KB |
Output is correct |
6 |
Correct |
5 ms |
37468 KB |
Output is correct |
7 |
Correct |
4 ms |
37468 KB |
Output is correct |
8 |
Correct |
6 ms |
37468 KB |
Output is correct |
9 |
Correct |
6 ms |
37468 KB |
Output is correct |
10 |
Correct |
5 ms |
37468 KB |
Output is correct |
11 |
Correct |
4 ms |
37468 KB |
Output is correct |
12 |
Correct |
5 ms |
37468 KB |
Output is correct |
13 |
Correct |
5 ms |
37468 KB |
Output is correct |
14 |
Correct |
5 ms |
37468 KB |
Output is correct |
15 |
Correct |
7 ms |
37356 KB |
Output is correct |
16 |
Correct |
5 ms |
37468 KB |
Output is correct |
17 |
Correct |
6 ms |
37468 KB |
Output is correct |
18 |
Correct |
5 ms |
37468 KB |
Output is correct |
19 |
Correct |
6 ms |
37468 KB |
Output is correct |
20 |
Correct |
6 ms |
37468 KB |
Output is correct |
21 |
Correct |
5 ms |
37584 KB |
Output is correct |
22 |
Correct |
5 ms |
37468 KB |
Output is correct |
23 |
Correct |
5 ms |
37392 KB |
Output is correct |
24 |
Correct |
6 ms |
37468 KB |
Output is correct |
25 |
Correct |
4 ms |
37468 KB |
Output is correct |
26 |
Correct |
5 ms |
37468 KB |
Output is correct |
27 |
Correct |
18 ms |
40028 KB |
Output is correct |
28 |
Correct |
15 ms |
40108 KB |
Output is correct |
29 |
Correct |
15 ms |
40540 KB |
Output is correct |
30 |
Correct |
14 ms |
40516 KB |
Output is correct |
31 |
Correct |
12 ms |
40028 KB |
Output is correct |
32 |
Correct |
14 ms |
40304 KB |
Output is correct |
33 |
Correct |
15 ms |
40572 KB |
Output is correct |
34 |
Correct |
13 ms |
40448 KB |
Output is correct |
35 |
Correct |
17 ms |
40028 KB |
Output is correct |
36 |
Correct |
13 ms |
40228 KB |
Output is correct |
37 |
Correct |
13 ms |
40536 KB |
Output is correct |
38 |
Correct |
14 ms |
40512 KB |
Output is correct |
39 |
Correct |
13 ms |
40520 KB |
Output is correct |
40 |
Correct |
12 ms |
40304 KB |
Output is correct |
41 |
Correct |
18 ms |
40284 KB |
Output is correct |
42 |
Correct |
13 ms |
40092 KB |
Output is correct |
43 |
Correct |
13 ms |
40280 KB |
Output is correct |
44 |
Correct |
16 ms |
40284 KB |
Output is correct |
45 |
Correct |
15 ms |
40284 KB |
Output is correct |
46 |
Correct |
12 ms |
40028 KB |
Output is correct |
47 |
Correct |
12 ms |
40120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
37468 KB |
Output is correct |
2 |
Correct |
5 ms |
37468 KB |
Output is correct |
3 |
Correct |
5 ms |
37468 KB |
Output is correct |
4 |
Correct |
5 ms |
37468 KB |
Output is correct |
5 |
Correct |
5 ms |
37464 KB |
Output is correct |
6 |
Correct |
5 ms |
37468 KB |
Output is correct |
7 |
Correct |
4 ms |
37468 KB |
Output is correct |
8 |
Correct |
6 ms |
37468 KB |
Output is correct |
9 |
Correct |
6 ms |
37468 KB |
Output is correct |
10 |
Correct |
5 ms |
37468 KB |
Output is correct |
11 |
Correct |
4 ms |
37468 KB |
Output is correct |
12 |
Correct |
5 ms |
37468 KB |
Output is correct |
13 |
Correct |
5 ms |
37468 KB |
Output is correct |
14 |
Correct |
5 ms |
37468 KB |
Output is correct |
15 |
Correct |
7 ms |
37356 KB |
Output is correct |
16 |
Correct |
5 ms |
37468 KB |
Output is correct |
17 |
Correct |
6 ms |
37468 KB |
Output is correct |
18 |
Correct |
5 ms |
37468 KB |
Output is correct |
19 |
Correct |
6 ms |
37468 KB |
Output is correct |
20 |
Correct |
6 ms |
37468 KB |
Output is correct |
21 |
Correct |
5 ms |
37584 KB |
Output is correct |
22 |
Correct |
5 ms |
37468 KB |
Output is correct |
23 |
Correct |
5 ms |
37392 KB |
Output is correct |
24 |
Correct |
6 ms |
37468 KB |
Output is correct |
25 |
Correct |
4 ms |
37468 KB |
Output is correct |
26 |
Correct |
5 ms |
37468 KB |
Output is correct |
27 |
Correct |
18 ms |
40028 KB |
Output is correct |
28 |
Correct |
15 ms |
40108 KB |
Output is correct |
29 |
Correct |
15 ms |
40540 KB |
Output is correct |
30 |
Correct |
14 ms |
40516 KB |
Output is correct |
31 |
Correct |
12 ms |
40028 KB |
Output is correct |
32 |
Correct |
14 ms |
40304 KB |
Output is correct |
33 |
Correct |
15 ms |
40572 KB |
Output is correct |
34 |
Correct |
13 ms |
40448 KB |
Output is correct |
35 |
Correct |
17 ms |
40028 KB |
Output is correct |
36 |
Correct |
13 ms |
40228 KB |
Output is correct |
37 |
Correct |
13 ms |
40536 KB |
Output is correct |
38 |
Correct |
14 ms |
40512 KB |
Output is correct |
39 |
Correct |
13 ms |
40520 KB |
Output is correct |
40 |
Correct |
12 ms |
40304 KB |
Output is correct |
41 |
Correct |
18 ms |
40284 KB |
Output is correct |
42 |
Correct |
13 ms |
40092 KB |
Output is correct |
43 |
Correct |
13 ms |
40280 KB |
Output is correct |
44 |
Correct |
16 ms |
40284 KB |
Output is correct |
45 |
Correct |
15 ms |
40284 KB |
Output is correct |
46 |
Correct |
12 ms |
40028 KB |
Output is correct |
47 |
Correct |
12 ms |
40120 KB |
Output is correct |
48 |
Correct |
127 ms |
49772 KB |
Output is correct |
49 |
Correct |
91 ms |
49932 KB |
Output is correct |
50 |
Correct |
107 ms |
52168 KB |
Output is correct |
51 |
Correct |
119 ms |
51908 KB |
Output is correct |
52 |
Correct |
90 ms |
51084 KB |
Output is correct |
53 |
Correct |
82 ms |
48980 KB |
Output is correct |
54 |
Correct |
76 ms |
48156 KB |
Output is correct |
55 |
Correct |
76 ms |
47948 KB |
Output is correct |
56 |
Correct |
95 ms |
47696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
37468 KB |
Output is correct |
2 |
Correct |
5 ms |
37468 KB |
Output is correct |
3 |
Correct |
5 ms |
37468 KB |
Output is correct |
4 |
Correct |
5 ms |
37468 KB |
Output is correct |
5 |
Correct |
5 ms |
37464 KB |
Output is correct |
6 |
Correct |
5 ms |
37468 KB |
Output is correct |
7 |
Correct |
4 ms |
37468 KB |
Output is correct |
8 |
Correct |
6 ms |
37468 KB |
Output is correct |
9 |
Correct |
6 ms |
37468 KB |
Output is correct |
10 |
Correct |
5 ms |
37468 KB |
Output is correct |
11 |
Correct |
4 ms |
37468 KB |
Output is correct |
12 |
Correct |
5 ms |
37468 KB |
Output is correct |
13 |
Correct |
5 ms |
37468 KB |
Output is correct |
14 |
Correct |
5 ms |
37468 KB |
Output is correct |
15 |
Correct |
7 ms |
37356 KB |
Output is correct |
16 |
Correct |
5 ms |
37468 KB |
Output is correct |
17 |
Correct |
6 ms |
37468 KB |
Output is correct |
18 |
Correct |
5 ms |
37468 KB |
Output is correct |
19 |
Correct |
6 ms |
37468 KB |
Output is correct |
20 |
Correct |
6 ms |
37468 KB |
Output is correct |
21 |
Correct |
5 ms |
37584 KB |
Output is correct |
22 |
Correct |
5 ms |
37468 KB |
Output is correct |
23 |
Correct |
5 ms |
37392 KB |
Output is correct |
24 |
Correct |
6 ms |
37468 KB |
Output is correct |
25 |
Correct |
4 ms |
37468 KB |
Output is correct |
26 |
Correct |
5 ms |
37468 KB |
Output is correct |
27 |
Correct |
18 ms |
40028 KB |
Output is correct |
28 |
Correct |
15 ms |
40108 KB |
Output is correct |
29 |
Correct |
15 ms |
40540 KB |
Output is correct |
30 |
Correct |
14 ms |
40516 KB |
Output is correct |
31 |
Correct |
12 ms |
40028 KB |
Output is correct |
32 |
Correct |
14 ms |
40304 KB |
Output is correct |
33 |
Correct |
15 ms |
40572 KB |
Output is correct |
34 |
Correct |
13 ms |
40448 KB |
Output is correct |
35 |
Correct |
17 ms |
40028 KB |
Output is correct |
36 |
Correct |
13 ms |
40228 KB |
Output is correct |
37 |
Correct |
13 ms |
40536 KB |
Output is correct |
38 |
Correct |
14 ms |
40512 KB |
Output is correct |
39 |
Correct |
13 ms |
40520 KB |
Output is correct |
40 |
Correct |
12 ms |
40304 KB |
Output is correct |
41 |
Correct |
18 ms |
40284 KB |
Output is correct |
42 |
Correct |
13 ms |
40092 KB |
Output is correct |
43 |
Correct |
13 ms |
40280 KB |
Output is correct |
44 |
Correct |
16 ms |
40284 KB |
Output is correct |
45 |
Correct |
15 ms |
40284 KB |
Output is correct |
46 |
Correct |
12 ms |
40028 KB |
Output is correct |
47 |
Correct |
12 ms |
40120 KB |
Output is correct |
48 |
Correct |
127 ms |
49772 KB |
Output is correct |
49 |
Correct |
91 ms |
49932 KB |
Output is correct |
50 |
Correct |
107 ms |
52168 KB |
Output is correct |
51 |
Correct |
119 ms |
51908 KB |
Output is correct |
52 |
Correct |
90 ms |
51084 KB |
Output is correct |
53 |
Correct |
82 ms |
48980 KB |
Output is correct |
54 |
Correct |
76 ms |
48156 KB |
Output is correct |
55 |
Correct |
76 ms |
47948 KB |
Output is correct |
56 |
Correct |
95 ms |
47696 KB |
Output is correct |
57 |
Correct |
427 ms |
83576 KB |
Output is correct |
58 |
Correct |
372 ms |
74876 KB |
Output is correct |
59 |
Correct |
334 ms |
74912 KB |
Output is correct |
60 |
Correct |
391 ms |
78828 KB |
Output is correct |
61 |
Correct |
381 ms |
78672 KB |
Output is correct |
62 |
Correct |
171 ms |
64336 KB |
Output is correct |
63 |
Correct |
210 ms |
68428 KB |
Output is correct |
64 |
Correct |
193 ms |
65792 KB |
Output is correct |
65 |
Correct |
119 ms |
58960 KB |
Output is correct |