# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
51321 |
2018-06-17T13:15:42 Z |
ho94949 |
Rope (JOI17_rope) |
C++17 |
|
2495 ms |
144580 KB |
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1048576;
int idx[2*MAXN];
int getv(int a, int b)
{
a += MAXN; b += MAXN;
int ans = 0;
while(a<=b)
{
if(a%2==1) ans = max(ans, idx[a++]);
if(b%2==0) ans = max(ans, idx[b--]);
a/=2; b/=2;
}
return ans;
}
void setv(int a, int v)
{
idx[a+=MAXN] = v;
while((a=a/2))
idx[a] = max(idx[2*a], idx[2*a+1]);
}
void addv(int a, int v)
{
idx[a+=MAXN] += v;
while((a=a/2))
idx[a] = max(idx[2*a], idx[2*a+1]);
}
int N, K;
vector<int> adj[MAXN];
int arr[MAXN];
int anseven[MAXN], ansodd[MAXN];
void even()
{
for(int i=0; i<N/2; ++i)
{
int l = arr[2*i], r = arr[2*i+1];
if(l == r)
addv(l, 2);
else
{
addv(l, 1); addv(r, 1);
adj[l].push_back(r);
adj[r].push_back(l);
}
}
if(N%2==1) addv(arr[N-1], 1);
for(int c=1; c<=K; ++c)
{
for(auto x: adj[c])
addv(x, -1);
anseven[c] = (getv(c, c) + max(getv(1, c-1), getv(c+1, K)));
for(auto x: adj[c])
addv(x, +1);
}
}
void odd()
{
addv(arr[0], 1);
for(int i=0; i<(N-1)/2; ++i)
{
int l = arr[2*i+1], r = arr[2*i+2];
if(l == r)
addv(l, 2);
else
{
addv(l, 1); addv(r, 1);
adj[l].push_back(r);
adj[r].push_back(l);
}
}
if(N%2==0) addv(arr[N-1], 1);
for(int c=1; c<=K; ++c)
{
for(auto x: adj[c])
addv(x, -1);
ansodd[c] = (getv(c, c) + max(getv(1, c-1), getv(c+1, K)));
for(auto x: adj[c])
addv(x, +1);
}
}
int main()
{
scanf("%d%d", &N, &K);
for(int i=0; i<N; ++i) scanf("%d", arr+i);
even();
for(int i=1; i<=K; ++i) adj[i].clear();
memset(idx, 0, sizeof idx);
odd();
for(int i=1; i<=K; ++i)
printf("%d\n", N-max(anseven[i], ansodd[i]));
return 0;
}
Compilation message
rope.cpp: In function 'int main()':
rope.cpp:95:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &K);
~~~~~^~~~~~~~~~~~~~~~
rope.cpp:96:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=0; i<N; ++i) scanf("%d", arr+i);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
33148 KB |
Output is correct |
2 |
Correct |
31 ms |
33328 KB |
Output is correct |
3 |
Correct |
28 ms |
33364 KB |
Output is correct |
4 |
Correct |
39 ms |
33440 KB |
Output is correct |
5 |
Correct |
28 ms |
33440 KB |
Output is correct |
6 |
Correct |
27 ms |
33440 KB |
Output is correct |
7 |
Correct |
28 ms |
33480 KB |
Output is correct |
8 |
Correct |
27 ms |
33480 KB |
Output is correct |
9 |
Correct |
27 ms |
33480 KB |
Output is correct |
10 |
Correct |
27 ms |
33480 KB |
Output is correct |
11 |
Correct |
28 ms |
33480 KB |
Output is correct |
12 |
Correct |
28 ms |
33480 KB |
Output is correct |
13 |
Correct |
29 ms |
33480 KB |
Output is correct |
14 |
Correct |
31 ms |
33480 KB |
Output is correct |
15 |
Correct |
28 ms |
33480 KB |
Output is correct |
16 |
Correct |
28 ms |
33480 KB |
Output is correct |
17 |
Correct |
28 ms |
33480 KB |
Output is correct |
18 |
Correct |
29 ms |
33480 KB |
Output is correct |
19 |
Correct |
29 ms |
33480 KB |
Output is correct |
20 |
Correct |
28 ms |
33480 KB |
Output is correct |
21 |
Correct |
29 ms |
33480 KB |
Output is correct |
22 |
Correct |
28 ms |
33480 KB |
Output is correct |
23 |
Correct |
29 ms |
33480 KB |
Output is correct |
24 |
Correct |
28 ms |
33480 KB |
Output is correct |
25 |
Correct |
27 ms |
33480 KB |
Output is correct |
26 |
Correct |
27 ms |
33480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
33148 KB |
Output is correct |
2 |
Correct |
31 ms |
33328 KB |
Output is correct |
3 |
Correct |
28 ms |
33364 KB |
Output is correct |
4 |
Correct |
39 ms |
33440 KB |
Output is correct |
5 |
Correct |
28 ms |
33440 KB |
Output is correct |
6 |
Correct |
27 ms |
33440 KB |
Output is correct |
7 |
Correct |
28 ms |
33480 KB |
Output is correct |
8 |
Correct |
27 ms |
33480 KB |
Output is correct |
9 |
Correct |
27 ms |
33480 KB |
Output is correct |
10 |
Correct |
27 ms |
33480 KB |
Output is correct |
11 |
Correct |
28 ms |
33480 KB |
Output is correct |
12 |
Correct |
28 ms |
33480 KB |
Output is correct |
13 |
Correct |
29 ms |
33480 KB |
Output is correct |
14 |
Correct |
31 ms |
33480 KB |
Output is correct |
15 |
Correct |
28 ms |
33480 KB |
Output is correct |
16 |
Correct |
28 ms |
33480 KB |
Output is correct |
17 |
Correct |
28 ms |
33480 KB |
Output is correct |
18 |
Correct |
29 ms |
33480 KB |
Output is correct |
19 |
Correct |
29 ms |
33480 KB |
Output is correct |
20 |
Correct |
28 ms |
33480 KB |
Output is correct |
21 |
Correct |
29 ms |
33480 KB |
Output is correct |
22 |
Correct |
28 ms |
33480 KB |
Output is correct |
23 |
Correct |
29 ms |
33480 KB |
Output is correct |
24 |
Correct |
28 ms |
33480 KB |
Output is correct |
25 |
Correct |
27 ms |
33480 KB |
Output is correct |
26 |
Correct |
27 ms |
33480 KB |
Output is correct |
27 |
Correct |
82 ms |
34480 KB |
Output is correct |
28 |
Correct |
75 ms |
34480 KB |
Output is correct |
29 |
Correct |
79 ms |
34480 KB |
Output is correct |
30 |
Correct |
80 ms |
34480 KB |
Output is correct |
31 |
Correct |
83 ms |
34480 KB |
Output is correct |
32 |
Correct |
75 ms |
34480 KB |
Output is correct |
33 |
Correct |
93 ms |
34480 KB |
Output is correct |
34 |
Correct |
83 ms |
34480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
33148 KB |
Output is correct |
2 |
Correct |
31 ms |
33328 KB |
Output is correct |
3 |
Correct |
28 ms |
33364 KB |
Output is correct |
4 |
Correct |
39 ms |
33440 KB |
Output is correct |
5 |
Correct |
28 ms |
33440 KB |
Output is correct |
6 |
Correct |
27 ms |
33440 KB |
Output is correct |
7 |
Correct |
28 ms |
33480 KB |
Output is correct |
8 |
Correct |
27 ms |
33480 KB |
Output is correct |
9 |
Correct |
27 ms |
33480 KB |
Output is correct |
10 |
Correct |
27 ms |
33480 KB |
Output is correct |
11 |
Correct |
28 ms |
33480 KB |
Output is correct |
12 |
Correct |
28 ms |
33480 KB |
Output is correct |
13 |
Correct |
29 ms |
33480 KB |
Output is correct |
14 |
Correct |
31 ms |
33480 KB |
Output is correct |
15 |
Correct |
28 ms |
33480 KB |
Output is correct |
16 |
Correct |
28 ms |
33480 KB |
Output is correct |
17 |
Correct |
28 ms |
33480 KB |
Output is correct |
18 |
Correct |
29 ms |
33480 KB |
Output is correct |
19 |
Correct |
29 ms |
33480 KB |
Output is correct |
20 |
Correct |
28 ms |
33480 KB |
Output is correct |
21 |
Correct |
29 ms |
33480 KB |
Output is correct |
22 |
Correct |
28 ms |
33480 KB |
Output is correct |
23 |
Correct |
29 ms |
33480 KB |
Output is correct |
24 |
Correct |
28 ms |
33480 KB |
Output is correct |
25 |
Correct |
27 ms |
33480 KB |
Output is correct |
26 |
Correct |
27 ms |
33480 KB |
Output is correct |
27 |
Correct |
82 ms |
34480 KB |
Output is correct |
28 |
Correct |
75 ms |
34480 KB |
Output is correct |
29 |
Correct |
79 ms |
34480 KB |
Output is correct |
30 |
Correct |
80 ms |
34480 KB |
Output is correct |
31 |
Correct |
83 ms |
34480 KB |
Output is correct |
32 |
Correct |
75 ms |
34480 KB |
Output is correct |
33 |
Correct |
93 ms |
34480 KB |
Output is correct |
34 |
Correct |
83 ms |
34480 KB |
Output is correct |
35 |
Correct |
77 ms |
34480 KB |
Output is correct |
36 |
Correct |
75 ms |
34480 KB |
Output is correct |
37 |
Correct |
87 ms |
34480 KB |
Output is correct |
38 |
Correct |
80 ms |
34480 KB |
Output is correct |
39 |
Correct |
80 ms |
34480 KB |
Output is correct |
40 |
Correct |
76 ms |
34552 KB |
Output is correct |
41 |
Correct |
75 ms |
34552 KB |
Output is correct |
42 |
Correct |
76 ms |
34552 KB |
Output is correct |
43 |
Correct |
115 ms |
34552 KB |
Output is correct |
44 |
Correct |
114 ms |
34552 KB |
Output is correct |
45 |
Correct |
95 ms |
34672 KB |
Output is correct |
46 |
Correct |
74 ms |
34672 KB |
Output is correct |
47 |
Correct |
81 ms |
34696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
33148 KB |
Output is correct |
2 |
Correct |
31 ms |
33328 KB |
Output is correct |
3 |
Correct |
28 ms |
33364 KB |
Output is correct |
4 |
Correct |
39 ms |
33440 KB |
Output is correct |
5 |
Correct |
28 ms |
33440 KB |
Output is correct |
6 |
Correct |
27 ms |
33440 KB |
Output is correct |
7 |
Correct |
28 ms |
33480 KB |
Output is correct |
8 |
Correct |
27 ms |
33480 KB |
Output is correct |
9 |
Correct |
27 ms |
33480 KB |
Output is correct |
10 |
Correct |
27 ms |
33480 KB |
Output is correct |
11 |
Correct |
28 ms |
33480 KB |
Output is correct |
12 |
Correct |
28 ms |
33480 KB |
Output is correct |
13 |
Correct |
29 ms |
33480 KB |
Output is correct |
14 |
Correct |
31 ms |
33480 KB |
Output is correct |
15 |
Correct |
28 ms |
33480 KB |
Output is correct |
16 |
Correct |
28 ms |
33480 KB |
Output is correct |
17 |
Correct |
28 ms |
33480 KB |
Output is correct |
18 |
Correct |
29 ms |
33480 KB |
Output is correct |
19 |
Correct |
29 ms |
33480 KB |
Output is correct |
20 |
Correct |
28 ms |
33480 KB |
Output is correct |
21 |
Correct |
29 ms |
33480 KB |
Output is correct |
22 |
Correct |
28 ms |
33480 KB |
Output is correct |
23 |
Correct |
29 ms |
33480 KB |
Output is correct |
24 |
Correct |
28 ms |
33480 KB |
Output is correct |
25 |
Correct |
27 ms |
33480 KB |
Output is correct |
26 |
Correct |
27 ms |
33480 KB |
Output is correct |
27 |
Correct |
82 ms |
34480 KB |
Output is correct |
28 |
Correct |
75 ms |
34480 KB |
Output is correct |
29 |
Correct |
79 ms |
34480 KB |
Output is correct |
30 |
Correct |
80 ms |
34480 KB |
Output is correct |
31 |
Correct |
83 ms |
34480 KB |
Output is correct |
32 |
Correct |
75 ms |
34480 KB |
Output is correct |
33 |
Correct |
93 ms |
34480 KB |
Output is correct |
34 |
Correct |
83 ms |
34480 KB |
Output is correct |
35 |
Correct |
77 ms |
34480 KB |
Output is correct |
36 |
Correct |
75 ms |
34480 KB |
Output is correct |
37 |
Correct |
87 ms |
34480 KB |
Output is correct |
38 |
Correct |
80 ms |
34480 KB |
Output is correct |
39 |
Correct |
80 ms |
34480 KB |
Output is correct |
40 |
Correct |
76 ms |
34552 KB |
Output is correct |
41 |
Correct |
75 ms |
34552 KB |
Output is correct |
42 |
Correct |
76 ms |
34552 KB |
Output is correct |
43 |
Correct |
115 ms |
34552 KB |
Output is correct |
44 |
Correct |
114 ms |
34552 KB |
Output is correct |
45 |
Correct |
95 ms |
34672 KB |
Output is correct |
46 |
Correct |
74 ms |
34672 KB |
Output is correct |
47 |
Correct |
81 ms |
34696 KB |
Output is correct |
48 |
Correct |
655 ms |
44020 KB |
Output is correct |
49 |
Correct |
585 ms |
48636 KB |
Output is correct |
50 |
Correct |
544 ms |
53208 KB |
Output is correct |
51 |
Correct |
575 ms |
57476 KB |
Output is correct |
52 |
Correct |
550 ms |
60120 KB |
Output is correct |
53 |
Correct |
526 ms |
64884 KB |
Output is correct |
54 |
Correct |
504 ms |
68460 KB |
Output is correct |
55 |
Correct |
510 ms |
72724 KB |
Output is correct |
56 |
Correct |
550 ms |
76992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
33148 KB |
Output is correct |
2 |
Correct |
31 ms |
33328 KB |
Output is correct |
3 |
Correct |
28 ms |
33364 KB |
Output is correct |
4 |
Correct |
39 ms |
33440 KB |
Output is correct |
5 |
Correct |
28 ms |
33440 KB |
Output is correct |
6 |
Correct |
27 ms |
33440 KB |
Output is correct |
7 |
Correct |
28 ms |
33480 KB |
Output is correct |
8 |
Correct |
27 ms |
33480 KB |
Output is correct |
9 |
Correct |
27 ms |
33480 KB |
Output is correct |
10 |
Correct |
27 ms |
33480 KB |
Output is correct |
11 |
Correct |
28 ms |
33480 KB |
Output is correct |
12 |
Correct |
28 ms |
33480 KB |
Output is correct |
13 |
Correct |
29 ms |
33480 KB |
Output is correct |
14 |
Correct |
31 ms |
33480 KB |
Output is correct |
15 |
Correct |
28 ms |
33480 KB |
Output is correct |
16 |
Correct |
28 ms |
33480 KB |
Output is correct |
17 |
Correct |
28 ms |
33480 KB |
Output is correct |
18 |
Correct |
29 ms |
33480 KB |
Output is correct |
19 |
Correct |
29 ms |
33480 KB |
Output is correct |
20 |
Correct |
28 ms |
33480 KB |
Output is correct |
21 |
Correct |
29 ms |
33480 KB |
Output is correct |
22 |
Correct |
28 ms |
33480 KB |
Output is correct |
23 |
Correct |
29 ms |
33480 KB |
Output is correct |
24 |
Correct |
28 ms |
33480 KB |
Output is correct |
25 |
Correct |
27 ms |
33480 KB |
Output is correct |
26 |
Correct |
27 ms |
33480 KB |
Output is correct |
27 |
Correct |
82 ms |
34480 KB |
Output is correct |
28 |
Correct |
75 ms |
34480 KB |
Output is correct |
29 |
Correct |
79 ms |
34480 KB |
Output is correct |
30 |
Correct |
80 ms |
34480 KB |
Output is correct |
31 |
Correct |
83 ms |
34480 KB |
Output is correct |
32 |
Correct |
75 ms |
34480 KB |
Output is correct |
33 |
Correct |
93 ms |
34480 KB |
Output is correct |
34 |
Correct |
83 ms |
34480 KB |
Output is correct |
35 |
Correct |
77 ms |
34480 KB |
Output is correct |
36 |
Correct |
75 ms |
34480 KB |
Output is correct |
37 |
Correct |
87 ms |
34480 KB |
Output is correct |
38 |
Correct |
80 ms |
34480 KB |
Output is correct |
39 |
Correct |
80 ms |
34480 KB |
Output is correct |
40 |
Correct |
76 ms |
34552 KB |
Output is correct |
41 |
Correct |
75 ms |
34552 KB |
Output is correct |
42 |
Correct |
76 ms |
34552 KB |
Output is correct |
43 |
Correct |
115 ms |
34552 KB |
Output is correct |
44 |
Correct |
114 ms |
34552 KB |
Output is correct |
45 |
Correct |
95 ms |
34672 KB |
Output is correct |
46 |
Correct |
74 ms |
34672 KB |
Output is correct |
47 |
Correct |
81 ms |
34696 KB |
Output is correct |
48 |
Correct |
655 ms |
44020 KB |
Output is correct |
49 |
Correct |
585 ms |
48636 KB |
Output is correct |
50 |
Correct |
544 ms |
53208 KB |
Output is correct |
51 |
Correct |
575 ms |
57476 KB |
Output is correct |
52 |
Correct |
550 ms |
60120 KB |
Output is correct |
53 |
Correct |
526 ms |
64884 KB |
Output is correct |
54 |
Correct |
504 ms |
68460 KB |
Output is correct |
55 |
Correct |
510 ms |
72724 KB |
Output is correct |
56 |
Correct |
550 ms |
76992 KB |
Output is correct |
57 |
Correct |
2495 ms |
125388 KB |
Output is correct |
58 |
Correct |
1998 ms |
125388 KB |
Output is correct |
59 |
Correct |
2096 ms |
125388 KB |
Output is correct |
60 |
Correct |
2155 ms |
131536 KB |
Output is correct |
61 |
Correct |
2131 ms |
138284 KB |
Output is correct |
62 |
Correct |
1059 ms |
138284 KB |
Output is correct |
63 |
Correct |
1296 ms |
141028 KB |
Output is correct |
64 |
Correct |
1158 ms |
144580 KB |
Output is correct |
65 |
Correct |
833 ms |
144580 KB |
Output is correct |