# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
128682 |
2019-07-11T08:23:49 Z |
송준혁(#3162) |
Rope (JOI17_rope) |
C++14 |
|
2500 ms |
133488 KB |
#include <bits/stdc++.h>
using namespace std;
int N, M;
int A[1010101];
vector<int> O[1010101], E[1010101];
int cnt[1010101];
int T[4040404];
void init(int id, int s, int e){
if (s == e){
T[id] = cnt[s];
return;
}
int mid = (s+e)/2;
init(id*2, s, mid);
init(id*2+1, mid+1, e);
T[id] = max(T[id*2], T[id*2+1]);
}
void update(int t, int v){
int id=1, s=1, e=M;
while (s < e){
if (((s+e)>>1) < t) id = (id<<1)+1, s = ((s+e)>>1) + 1;
else id = id<<1, e = (s+e)>>1;
}
T[id] += v;
id>>=1;
while (id){
T[id] = max(T[id*2], T[id*2+1]);
id>>=1;
}
}
int RMQ(int id, int s, int e, int ts, int te){
if (e < ts || te < s) return 0;
if (ts <= s && e <= te) return T[id];
int mid = (s+e)/2;
return max(RMQ(id*2, s, mid, ts, te), RMQ(id*2+1, mid+1, e, ts, te));
}
int main(){
scanf("%d %d", &N, &M);
for (int i=1; i<=N; i++){
scanf("%d", &A[i]);
cnt[A[i]]++;
}
for (int i=1; i<N; i++){
if (A[i] == A[i+1]) continue;
if (i & 1){
E[A[i]].push_back(A[i+1]);
E[A[i+1]].push_back(A[i]);
}
else{
O[A[i]].push_back(A[i+1]);
O[A[i+1]].push_back(A[i]);
}
}
init(1, 1, M);
for (int i=1; i<=M; i++){
for (int x : O[i]) update(x, -1);
int oret = cnt[i] + max(RMQ(1, 1, M, 1, i-1), RMQ(1, 1, M, i+1, M));
for (int x : O[i]) update(x, 1);
for (int x : E[i]) update(x, -1);
int eret = cnt[i] + max(RMQ(1, 1, M, 1, i-1), RMQ(1, 1, M, i+1, M));
for (int x : E[i]) update(x, 1);
printf("%d\n", N - max(oret, eret));
}
return 0;
}
Compilation message
rope.cpp: In function 'int main()':
rope.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &N, &M);
~~~~~^~~~~~~~~~~~~~~~~
rope.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &A[i]);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
47736 KB |
Output is correct |
2 |
Correct |
45 ms |
47836 KB |
Output is correct |
3 |
Correct |
45 ms |
47736 KB |
Output is correct |
4 |
Correct |
45 ms |
47740 KB |
Output is correct |
5 |
Correct |
54 ms |
47736 KB |
Output is correct |
6 |
Correct |
52 ms |
47864 KB |
Output is correct |
7 |
Correct |
45 ms |
47740 KB |
Output is correct |
8 |
Correct |
45 ms |
47736 KB |
Output is correct |
9 |
Correct |
44 ms |
47736 KB |
Output is correct |
10 |
Correct |
45 ms |
47736 KB |
Output is correct |
11 |
Correct |
44 ms |
47736 KB |
Output is correct |
12 |
Correct |
45 ms |
47736 KB |
Output is correct |
13 |
Correct |
45 ms |
47824 KB |
Output is correct |
14 |
Correct |
44 ms |
47772 KB |
Output is correct |
15 |
Correct |
44 ms |
47736 KB |
Output is correct |
16 |
Correct |
44 ms |
47864 KB |
Output is correct |
17 |
Correct |
45 ms |
47748 KB |
Output is correct |
18 |
Correct |
44 ms |
47740 KB |
Output is correct |
19 |
Correct |
45 ms |
47736 KB |
Output is correct |
20 |
Correct |
44 ms |
47736 KB |
Output is correct |
21 |
Correct |
44 ms |
47736 KB |
Output is correct |
22 |
Correct |
45 ms |
47736 KB |
Output is correct |
23 |
Correct |
45 ms |
47740 KB |
Output is correct |
24 |
Correct |
45 ms |
47796 KB |
Output is correct |
25 |
Correct |
45 ms |
47736 KB |
Output is correct |
26 |
Correct |
46 ms |
47912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
47736 KB |
Output is correct |
2 |
Correct |
45 ms |
47836 KB |
Output is correct |
3 |
Correct |
45 ms |
47736 KB |
Output is correct |
4 |
Correct |
45 ms |
47740 KB |
Output is correct |
5 |
Correct |
54 ms |
47736 KB |
Output is correct |
6 |
Correct |
52 ms |
47864 KB |
Output is correct |
7 |
Correct |
45 ms |
47740 KB |
Output is correct |
8 |
Correct |
45 ms |
47736 KB |
Output is correct |
9 |
Correct |
44 ms |
47736 KB |
Output is correct |
10 |
Correct |
45 ms |
47736 KB |
Output is correct |
11 |
Correct |
44 ms |
47736 KB |
Output is correct |
12 |
Correct |
45 ms |
47736 KB |
Output is correct |
13 |
Correct |
45 ms |
47824 KB |
Output is correct |
14 |
Correct |
44 ms |
47772 KB |
Output is correct |
15 |
Correct |
44 ms |
47736 KB |
Output is correct |
16 |
Correct |
44 ms |
47864 KB |
Output is correct |
17 |
Correct |
45 ms |
47748 KB |
Output is correct |
18 |
Correct |
44 ms |
47740 KB |
Output is correct |
19 |
Correct |
45 ms |
47736 KB |
Output is correct |
20 |
Correct |
44 ms |
47736 KB |
Output is correct |
21 |
Correct |
44 ms |
47736 KB |
Output is correct |
22 |
Correct |
45 ms |
47736 KB |
Output is correct |
23 |
Correct |
45 ms |
47740 KB |
Output is correct |
24 |
Correct |
45 ms |
47796 KB |
Output is correct |
25 |
Correct |
45 ms |
47736 KB |
Output is correct |
26 |
Correct |
46 ms |
47912 KB |
Output is correct |
27 |
Correct |
66 ms |
49356 KB |
Output is correct |
28 |
Correct |
61 ms |
49140 KB |
Output is correct |
29 |
Correct |
67 ms |
49256 KB |
Output is correct |
30 |
Correct |
61 ms |
49024 KB |
Output is correct |
31 |
Correct |
66 ms |
49400 KB |
Output is correct |
32 |
Correct |
61 ms |
49144 KB |
Output is correct |
33 |
Correct |
65 ms |
49356 KB |
Output is correct |
34 |
Correct |
62 ms |
48888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
47736 KB |
Output is correct |
2 |
Correct |
45 ms |
47836 KB |
Output is correct |
3 |
Correct |
45 ms |
47736 KB |
Output is correct |
4 |
Correct |
45 ms |
47740 KB |
Output is correct |
5 |
Correct |
54 ms |
47736 KB |
Output is correct |
6 |
Correct |
52 ms |
47864 KB |
Output is correct |
7 |
Correct |
45 ms |
47740 KB |
Output is correct |
8 |
Correct |
45 ms |
47736 KB |
Output is correct |
9 |
Correct |
44 ms |
47736 KB |
Output is correct |
10 |
Correct |
45 ms |
47736 KB |
Output is correct |
11 |
Correct |
44 ms |
47736 KB |
Output is correct |
12 |
Correct |
45 ms |
47736 KB |
Output is correct |
13 |
Correct |
45 ms |
47824 KB |
Output is correct |
14 |
Correct |
44 ms |
47772 KB |
Output is correct |
15 |
Correct |
44 ms |
47736 KB |
Output is correct |
16 |
Correct |
44 ms |
47864 KB |
Output is correct |
17 |
Correct |
45 ms |
47748 KB |
Output is correct |
18 |
Correct |
44 ms |
47740 KB |
Output is correct |
19 |
Correct |
45 ms |
47736 KB |
Output is correct |
20 |
Correct |
44 ms |
47736 KB |
Output is correct |
21 |
Correct |
44 ms |
47736 KB |
Output is correct |
22 |
Correct |
45 ms |
47736 KB |
Output is correct |
23 |
Correct |
45 ms |
47740 KB |
Output is correct |
24 |
Correct |
45 ms |
47796 KB |
Output is correct |
25 |
Correct |
45 ms |
47736 KB |
Output is correct |
26 |
Correct |
46 ms |
47912 KB |
Output is correct |
27 |
Correct |
66 ms |
49356 KB |
Output is correct |
28 |
Correct |
61 ms |
49140 KB |
Output is correct |
29 |
Correct |
67 ms |
49256 KB |
Output is correct |
30 |
Correct |
61 ms |
49024 KB |
Output is correct |
31 |
Correct |
66 ms |
49400 KB |
Output is correct |
32 |
Correct |
61 ms |
49144 KB |
Output is correct |
33 |
Correct |
65 ms |
49356 KB |
Output is correct |
34 |
Correct |
62 ms |
48888 KB |
Output is correct |
35 |
Correct |
89 ms |
49400 KB |
Output is correct |
36 |
Correct |
89 ms |
49272 KB |
Output is correct |
37 |
Correct |
88 ms |
49272 KB |
Output is correct |
38 |
Correct |
89 ms |
49372 KB |
Output is correct |
39 |
Correct |
89 ms |
49272 KB |
Output is correct |
40 |
Correct |
84 ms |
49656 KB |
Output is correct |
41 |
Correct |
84 ms |
49528 KB |
Output is correct |
42 |
Correct |
82 ms |
49528 KB |
Output is correct |
43 |
Correct |
82 ms |
49528 KB |
Output is correct |
44 |
Correct |
86 ms |
49460 KB |
Output is correct |
45 |
Correct |
84 ms |
49528 KB |
Output is correct |
46 |
Correct |
81 ms |
49400 KB |
Output is correct |
47 |
Correct |
91 ms |
49656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
47736 KB |
Output is correct |
2 |
Correct |
45 ms |
47836 KB |
Output is correct |
3 |
Correct |
45 ms |
47736 KB |
Output is correct |
4 |
Correct |
45 ms |
47740 KB |
Output is correct |
5 |
Correct |
54 ms |
47736 KB |
Output is correct |
6 |
Correct |
52 ms |
47864 KB |
Output is correct |
7 |
Correct |
45 ms |
47740 KB |
Output is correct |
8 |
Correct |
45 ms |
47736 KB |
Output is correct |
9 |
Correct |
44 ms |
47736 KB |
Output is correct |
10 |
Correct |
45 ms |
47736 KB |
Output is correct |
11 |
Correct |
44 ms |
47736 KB |
Output is correct |
12 |
Correct |
45 ms |
47736 KB |
Output is correct |
13 |
Correct |
45 ms |
47824 KB |
Output is correct |
14 |
Correct |
44 ms |
47772 KB |
Output is correct |
15 |
Correct |
44 ms |
47736 KB |
Output is correct |
16 |
Correct |
44 ms |
47864 KB |
Output is correct |
17 |
Correct |
45 ms |
47748 KB |
Output is correct |
18 |
Correct |
44 ms |
47740 KB |
Output is correct |
19 |
Correct |
45 ms |
47736 KB |
Output is correct |
20 |
Correct |
44 ms |
47736 KB |
Output is correct |
21 |
Correct |
44 ms |
47736 KB |
Output is correct |
22 |
Correct |
45 ms |
47736 KB |
Output is correct |
23 |
Correct |
45 ms |
47740 KB |
Output is correct |
24 |
Correct |
45 ms |
47796 KB |
Output is correct |
25 |
Correct |
45 ms |
47736 KB |
Output is correct |
26 |
Correct |
46 ms |
47912 KB |
Output is correct |
27 |
Correct |
66 ms |
49356 KB |
Output is correct |
28 |
Correct |
61 ms |
49140 KB |
Output is correct |
29 |
Correct |
67 ms |
49256 KB |
Output is correct |
30 |
Correct |
61 ms |
49024 KB |
Output is correct |
31 |
Correct |
66 ms |
49400 KB |
Output is correct |
32 |
Correct |
61 ms |
49144 KB |
Output is correct |
33 |
Correct |
65 ms |
49356 KB |
Output is correct |
34 |
Correct |
62 ms |
48888 KB |
Output is correct |
35 |
Correct |
89 ms |
49400 KB |
Output is correct |
36 |
Correct |
89 ms |
49272 KB |
Output is correct |
37 |
Correct |
88 ms |
49272 KB |
Output is correct |
38 |
Correct |
89 ms |
49372 KB |
Output is correct |
39 |
Correct |
89 ms |
49272 KB |
Output is correct |
40 |
Correct |
84 ms |
49656 KB |
Output is correct |
41 |
Correct |
84 ms |
49528 KB |
Output is correct |
42 |
Correct |
82 ms |
49528 KB |
Output is correct |
43 |
Correct |
82 ms |
49528 KB |
Output is correct |
44 |
Correct |
86 ms |
49460 KB |
Output is correct |
45 |
Correct |
84 ms |
49528 KB |
Output is correct |
46 |
Correct |
81 ms |
49400 KB |
Output is correct |
47 |
Correct |
91 ms |
49656 KB |
Output is correct |
48 |
Correct |
598 ms |
65116 KB |
Output is correct |
49 |
Correct |
601 ms |
65228 KB |
Output is correct |
50 |
Correct |
609 ms |
64888 KB |
Output is correct |
51 |
Correct |
550 ms |
64888 KB |
Output is correct |
52 |
Correct |
513 ms |
62780 KB |
Output is correct |
53 |
Correct |
569 ms |
63520 KB |
Output is correct |
54 |
Correct |
554 ms |
61432 KB |
Output is correct |
55 |
Correct |
546 ms |
61048 KB |
Output is correct |
56 |
Correct |
544 ms |
60564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
47736 KB |
Output is correct |
2 |
Correct |
45 ms |
47836 KB |
Output is correct |
3 |
Correct |
45 ms |
47736 KB |
Output is correct |
4 |
Correct |
45 ms |
47740 KB |
Output is correct |
5 |
Correct |
54 ms |
47736 KB |
Output is correct |
6 |
Correct |
52 ms |
47864 KB |
Output is correct |
7 |
Correct |
45 ms |
47740 KB |
Output is correct |
8 |
Correct |
45 ms |
47736 KB |
Output is correct |
9 |
Correct |
44 ms |
47736 KB |
Output is correct |
10 |
Correct |
45 ms |
47736 KB |
Output is correct |
11 |
Correct |
44 ms |
47736 KB |
Output is correct |
12 |
Correct |
45 ms |
47736 KB |
Output is correct |
13 |
Correct |
45 ms |
47824 KB |
Output is correct |
14 |
Correct |
44 ms |
47772 KB |
Output is correct |
15 |
Correct |
44 ms |
47736 KB |
Output is correct |
16 |
Correct |
44 ms |
47864 KB |
Output is correct |
17 |
Correct |
45 ms |
47748 KB |
Output is correct |
18 |
Correct |
44 ms |
47740 KB |
Output is correct |
19 |
Correct |
45 ms |
47736 KB |
Output is correct |
20 |
Correct |
44 ms |
47736 KB |
Output is correct |
21 |
Correct |
44 ms |
47736 KB |
Output is correct |
22 |
Correct |
45 ms |
47736 KB |
Output is correct |
23 |
Correct |
45 ms |
47740 KB |
Output is correct |
24 |
Correct |
45 ms |
47796 KB |
Output is correct |
25 |
Correct |
45 ms |
47736 KB |
Output is correct |
26 |
Correct |
46 ms |
47912 KB |
Output is correct |
27 |
Correct |
66 ms |
49356 KB |
Output is correct |
28 |
Correct |
61 ms |
49140 KB |
Output is correct |
29 |
Correct |
67 ms |
49256 KB |
Output is correct |
30 |
Correct |
61 ms |
49024 KB |
Output is correct |
31 |
Correct |
66 ms |
49400 KB |
Output is correct |
32 |
Correct |
61 ms |
49144 KB |
Output is correct |
33 |
Correct |
65 ms |
49356 KB |
Output is correct |
34 |
Correct |
62 ms |
48888 KB |
Output is correct |
35 |
Correct |
89 ms |
49400 KB |
Output is correct |
36 |
Correct |
89 ms |
49272 KB |
Output is correct |
37 |
Correct |
88 ms |
49272 KB |
Output is correct |
38 |
Correct |
89 ms |
49372 KB |
Output is correct |
39 |
Correct |
89 ms |
49272 KB |
Output is correct |
40 |
Correct |
84 ms |
49656 KB |
Output is correct |
41 |
Correct |
84 ms |
49528 KB |
Output is correct |
42 |
Correct |
82 ms |
49528 KB |
Output is correct |
43 |
Correct |
82 ms |
49528 KB |
Output is correct |
44 |
Correct |
86 ms |
49460 KB |
Output is correct |
45 |
Correct |
84 ms |
49528 KB |
Output is correct |
46 |
Correct |
81 ms |
49400 KB |
Output is correct |
47 |
Correct |
91 ms |
49656 KB |
Output is correct |
48 |
Correct |
598 ms |
65116 KB |
Output is correct |
49 |
Correct |
601 ms |
65228 KB |
Output is correct |
50 |
Correct |
609 ms |
64888 KB |
Output is correct |
51 |
Correct |
550 ms |
64888 KB |
Output is correct |
52 |
Correct |
513 ms |
62780 KB |
Output is correct |
53 |
Correct |
569 ms |
63520 KB |
Output is correct |
54 |
Correct |
554 ms |
61432 KB |
Output is correct |
55 |
Correct |
546 ms |
61048 KB |
Output is correct |
56 |
Correct |
544 ms |
60564 KB |
Output is correct |
57 |
Execution timed out |
2546 ms |
133488 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |