# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
255702 |
2020-08-01T15:40:59 Z |
Namnamseo |
Rope (JOI17_rope) |
C++17 |
|
2500 ms |
81912 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
void read(int& x){ scanf("%d",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
int n, m;
int col[1000010];
int ans[1000010];
vector<int> adj[1000010];
int self[1000010];
const int M=1048576;
int t[M<<1];
void upd(int p, int v){
p+=M; t[p]+=v; p>>=1;
while(p) t[p]=max(t[p*2], t[p*2+1]), p>>=1;
}
int rM(int l, int r){
int ret=0;
l+=M; r+=M;
while(l<=r){
if(l&1) ret=max(ret, t[l++]);
if((r&1)==0) ret=max(ret, t[r--]);
l>>=1; r>>=1;
}
return ret;
}
void Do(){
for(auto& v:adj) v.clear(); memset(self, 0, sizeof(self)); memset(t, 0, sizeof(t));
for(int i=1; i<=n; i+=2){
if(i+1 <= n){
int a=col[i], b=col[i+1];
if(a == b){
++self[a];
upd(a, 2);
continue;
}
adj[a].pb(b); adj[b].pb(a);
upd(a, 1); upd(b, 1);
} else upd(col[i], 1);
}
for(int i=1; i<=m; ++i){
for(int x:adj[i]) upd(x, -1);
int jib=rM(i, i); upd(i, -jib);
ans[i]=min(ans[i],
n-rM(1, m)-jib
);
for(int x:adj[i]) upd(x, 1);
upd(i, jib);
}
}
void Do2(){
for(auto& v:adj) v.clear(); memset(self, 0, sizeof(self)); memset(t, 0, sizeof(t));
upd(col[1], 1);
for(int i=2; i<=n; i+=2){
if(i+1 <= n){
int a=col[i], b=col[i+1];
if(a == b){
++self[a];
upd(a, 2);
continue;
}
adj[a].pb(b); adj[b].pb(a);
upd(a, 1); upd(b, 1);
} else upd(col[i], 1);
}
for(int i=1; i<=m; ++i){
for(int x:adj[i]) upd(x, -1);
int jib=rM(i, i); upd(i, -jib);
ans[i]=min(ans[i],
n-rM(1, m)-jib
);
for(int x:adj[i]) upd(x, 1);
upd(i, jib);
}
}
int main()
{
read(n, m);
for(int i=1; i<=n; ++i) read(col[i]);
fill(ans+1, ans+m+1, n+1);
Do(); Do2();
reverse(col+1, col+n+1);
Do(); Do2();
for(int i=1; i<=m; ++i) printf("%d\n", ans[i]);
return 0;
}
Compilation message
rope.cpp: In function 'void Do()':
rope.cpp:39:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(auto& v:adj) v.clear(); memset(self, 0, sizeof(self)); memset(t, 0, sizeof(t));
^~~
rope.cpp:39:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for(auto& v:adj) v.clear(); memset(self, 0, sizeof(self)); memset(t, 0, sizeof(t));
^~~~~~
rope.cpp: In function 'void Do2()':
rope.cpp:66:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(auto& v:adj) v.clear(); memset(self, 0, sizeof(self)); memset(t, 0, sizeof(t));
^~~
rope.cpp:66:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for(auto& v:adj) v.clear(); memset(self, 0, sizeof(self)); memset(t, 0, sizeof(t));
^~~~~~
rope.cpp: In function 'void read(int&)':
rope.cpp:5:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
void read(int& x){ scanf("%d",&x); }
~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
35960 KB |
Output is correct |
2 |
Correct |
37 ms |
35968 KB |
Output is correct |
3 |
Correct |
44 ms |
35968 KB |
Output is correct |
4 |
Correct |
36 ms |
35968 KB |
Output is correct |
5 |
Correct |
43 ms |
35968 KB |
Output is correct |
6 |
Correct |
37 ms |
35968 KB |
Output is correct |
7 |
Correct |
36 ms |
35968 KB |
Output is correct |
8 |
Correct |
35 ms |
35968 KB |
Output is correct |
9 |
Correct |
36 ms |
35960 KB |
Output is correct |
10 |
Correct |
36 ms |
35960 KB |
Output is correct |
11 |
Correct |
37 ms |
35968 KB |
Output is correct |
12 |
Correct |
36 ms |
35968 KB |
Output is correct |
13 |
Correct |
36 ms |
35960 KB |
Output is correct |
14 |
Correct |
36 ms |
35968 KB |
Output is correct |
15 |
Correct |
39 ms |
35916 KB |
Output is correct |
16 |
Correct |
35 ms |
35960 KB |
Output is correct |
17 |
Correct |
40 ms |
35960 KB |
Output is correct |
18 |
Correct |
40 ms |
35968 KB |
Output is correct |
19 |
Correct |
43 ms |
35960 KB |
Output is correct |
20 |
Correct |
36 ms |
35968 KB |
Output is correct |
21 |
Correct |
37 ms |
35968 KB |
Output is correct |
22 |
Correct |
37 ms |
35968 KB |
Output is correct |
23 |
Correct |
36 ms |
35968 KB |
Output is correct |
24 |
Correct |
36 ms |
35968 KB |
Output is correct |
25 |
Correct |
37 ms |
35960 KB |
Output is correct |
26 |
Correct |
36 ms |
36088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
35960 KB |
Output is correct |
2 |
Correct |
37 ms |
35968 KB |
Output is correct |
3 |
Correct |
44 ms |
35968 KB |
Output is correct |
4 |
Correct |
36 ms |
35968 KB |
Output is correct |
5 |
Correct |
43 ms |
35968 KB |
Output is correct |
6 |
Correct |
37 ms |
35968 KB |
Output is correct |
7 |
Correct |
36 ms |
35968 KB |
Output is correct |
8 |
Correct |
35 ms |
35968 KB |
Output is correct |
9 |
Correct |
36 ms |
35960 KB |
Output is correct |
10 |
Correct |
36 ms |
35960 KB |
Output is correct |
11 |
Correct |
37 ms |
35968 KB |
Output is correct |
12 |
Correct |
36 ms |
35968 KB |
Output is correct |
13 |
Correct |
36 ms |
35960 KB |
Output is correct |
14 |
Correct |
36 ms |
35968 KB |
Output is correct |
15 |
Correct |
39 ms |
35916 KB |
Output is correct |
16 |
Correct |
35 ms |
35960 KB |
Output is correct |
17 |
Correct |
40 ms |
35960 KB |
Output is correct |
18 |
Correct |
40 ms |
35968 KB |
Output is correct |
19 |
Correct |
43 ms |
35960 KB |
Output is correct |
20 |
Correct |
36 ms |
35968 KB |
Output is correct |
21 |
Correct |
37 ms |
35968 KB |
Output is correct |
22 |
Correct |
37 ms |
35968 KB |
Output is correct |
23 |
Correct |
36 ms |
35968 KB |
Output is correct |
24 |
Correct |
36 ms |
35968 KB |
Output is correct |
25 |
Correct |
37 ms |
35960 KB |
Output is correct |
26 |
Correct |
36 ms |
36088 KB |
Output is correct |
27 |
Correct |
179 ms |
37188 KB |
Output is correct |
28 |
Correct |
172 ms |
37112 KB |
Output is correct |
29 |
Correct |
178 ms |
37240 KB |
Output is correct |
30 |
Correct |
164 ms |
36984 KB |
Output is correct |
31 |
Correct |
156 ms |
37112 KB |
Output is correct |
32 |
Correct |
161 ms |
37240 KB |
Output is correct |
33 |
Correct |
163 ms |
37112 KB |
Output is correct |
34 |
Correct |
157 ms |
36856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
35960 KB |
Output is correct |
2 |
Correct |
37 ms |
35968 KB |
Output is correct |
3 |
Correct |
44 ms |
35968 KB |
Output is correct |
4 |
Correct |
36 ms |
35968 KB |
Output is correct |
5 |
Correct |
43 ms |
35968 KB |
Output is correct |
6 |
Correct |
37 ms |
35968 KB |
Output is correct |
7 |
Correct |
36 ms |
35968 KB |
Output is correct |
8 |
Correct |
35 ms |
35968 KB |
Output is correct |
9 |
Correct |
36 ms |
35960 KB |
Output is correct |
10 |
Correct |
36 ms |
35960 KB |
Output is correct |
11 |
Correct |
37 ms |
35968 KB |
Output is correct |
12 |
Correct |
36 ms |
35968 KB |
Output is correct |
13 |
Correct |
36 ms |
35960 KB |
Output is correct |
14 |
Correct |
36 ms |
35968 KB |
Output is correct |
15 |
Correct |
39 ms |
35916 KB |
Output is correct |
16 |
Correct |
35 ms |
35960 KB |
Output is correct |
17 |
Correct |
40 ms |
35960 KB |
Output is correct |
18 |
Correct |
40 ms |
35968 KB |
Output is correct |
19 |
Correct |
43 ms |
35960 KB |
Output is correct |
20 |
Correct |
36 ms |
35968 KB |
Output is correct |
21 |
Correct |
37 ms |
35968 KB |
Output is correct |
22 |
Correct |
37 ms |
35968 KB |
Output is correct |
23 |
Correct |
36 ms |
35968 KB |
Output is correct |
24 |
Correct |
36 ms |
35968 KB |
Output is correct |
25 |
Correct |
37 ms |
35960 KB |
Output is correct |
26 |
Correct |
36 ms |
36088 KB |
Output is correct |
27 |
Correct |
179 ms |
37188 KB |
Output is correct |
28 |
Correct |
172 ms |
37112 KB |
Output is correct |
29 |
Correct |
178 ms |
37240 KB |
Output is correct |
30 |
Correct |
164 ms |
36984 KB |
Output is correct |
31 |
Correct |
156 ms |
37112 KB |
Output is correct |
32 |
Correct |
161 ms |
37240 KB |
Output is correct |
33 |
Correct |
163 ms |
37112 KB |
Output is correct |
34 |
Correct |
157 ms |
36856 KB |
Output is correct |
35 |
Correct |
127 ms |
37240 KB |
Output is correct |
36 |
Correct |
124 ms |
37240 KB |
Output is correct |
37 |
Correct |
119 ms |
37240 KB |
Output is correct |
38 |
Correct |
126 ms |
37240 KB |
Output is correct |
39 |
Correct |
125 ms |
37288 KB |
Output is correct |
40 |
Correct |
122 ms |
37368 KB |
Output is correct |
41 |
Correct |
116 ms |
37372 KB |
Output is correct |
42 |
Correct |
122 ms |
37368 KB |
Output is correct |
43 |
Correct |
119 ms |
37368 KB |
Output is correct |
44 |
Correct |
120 ms |
37368 KB |
Output is correct |
45 |
Correct |
115 ms |
37368 KB |
Output is correct |
46 |
Correct |
119 ms |
37368 KB |
Output is correct |
47 |
Correct |
120 ms |
37368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
35960 KB |
Output is correct |
2 |
Correct |
37 ms |
35968 KB |
Output is correct |
3 |
Correct |
44 ms |
35968 KB |
Output is correct |
4 |
Correct |
36 ms |
35968 KB |
Output is correct |
5 |
Correct |
43 ms |
35968 KB |
Output is correct |
6 |
Correct |
37 ms |
35968 KB |
Output is correct |
7 |
Correct |
36 ms |
35968 KB |
Output is correct |
8 |
Correct |
35 ms |
35968 KB |
Output is correct |
9 |
Correct |
36 ms |
35960 KB |
Output is correct |
10 |
Correct |
36 ms |
35960 KB |
Output is correct |
11 |
Correct |
37 ms |
35968 KB |
Output is correct |
12 |
Correct |
36 ms |
35968 KB |
Output is correct |
13 |
Correct |
36 ms |
35960 KB |
Output is correct |
14 |
Correct |
36 ms |
35968 KB |
Output is correct |
15 |
Correct |
39 ms |
35916 KB |
Output is correct |
16 |
Correct |
35 ms |
35960 KB |
Output is correct |
17 |
Correct |
40 ms |
35960 KB |
Output is correct |
18 |
Correct |
40 ms |
35968 KB |
Output is correct |
19 |
Correct |
43 ms |
35960 KB |
Output is correct |
20 |
Correct |
36 ms |
35968 KB |
Output is correct |
21 |
Correct |
37 ms |
35968 KB |
Output is correct |
22 |
Correct |
37 ms |
35968 KB |
Output is correct |
23 |
Correct |
36 ms |
35968 KB |
Output is correct |
24 |
Correct |
36 ms |
35968 KB |
Output is correct |
25 |
Correct |
37 ms |
35960 KB |
Output is correct |
26 |
Correct |
36 ms |
36088 KB |
Output is correct |
27 |
Correct |
179 ms |
37188 KB |
Output is correct |
28 |
Correct |
172 ms |
37112 KB |
Output is correct |
29 |
Correct |
178 ms |
37240 KB |
Output is correct |
30 |
Correct |
164 ms |
36984 KB |
Output is correct |
31 |
Correct |
156 ms |
37112 KB |
Output is correct |
32 |
Correct |
161 ms |
37240 KB |
Output is correct |
33 |
Correct |
163 ms |
37112 KB |
Output is correct |
34 |
Correct |
157 ms |
36856 KB |
Output is correct |
35 |
Correct |
127 ms |
37240 KB |
Output is correct |
36 |
Correct |
124 ms |
37240 KB |
Output is correct |
37 |
Correct |
119 ms |
37240 KB |
Output is correct |
38 |
Correct |
126 ms |
37240 KB |
Output is correct |
39 |
Correct |
125 ms |
37288 KB |
Output is correct |
40 |
Correct |
122 ms |
37368 KB |
Output is correct |
41 |
Correct |
116 ms |
37372 KB |
Output is correct |
42 |
Correct |
122 ms |
37368 KB |
Output is correct |
43 |
Correct |
119 ms |
37368 KB |
Output is correct |
44 |
Correct |
120 ms |
37368 KB |
Output is correct |
45 |
Correct |
115 ms |
37368 KB |
Output is correct |
46 |
Correct |
119 ms |
37368 KB |
Output is correct |
47 |
Correct |
120 ms |
37368 KB |
Output is correct |
48 |
Correct |
882 ms |
51192 KB |
Output is correct |
49 |
Correct |
876 ms |
51192 KB |
Output is correct |
50 |
Correct |
850 ms |
51168 KB |
Output is correct |
51 |
Correct |
875 ms |
50656 KB |
Output is correct |
52 |
Correct |
892 ms |
49400 KB |
Output is correct |
53 |
Correct |
869 ms |
50300 KB |
Output is correct |
54 |
Correct |
828 ms |
49400 KB |
Output is correct |
55 |
Correct |
854 ms |
49144 KB |
Output is correct |
56 |
Correct |
845 ms |
48888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
35960 KB |
Output is correct |
2 |
Correct |
37 ms |
35968 KB |
Output is correct |
3 |
Correct |
44 ms |
35968 KB |
Output is correct |
4 |
Correct |
36 ms |
35968 KB |
Output is correct |
5 |
Correct |
43 ms |
35968 KB |
Output is correct |
6 |
Correct |
37 ms |
35968 KB |
Output is correct |
7 |
Correct |
36 ms |
35968 KB |
Output is correct |
8 |
Correct |
35 ms |
35968 KB |
Output is correct |
9 |
Correct |
36 ms |
35960 KB |
Output is correct |
10 |
Correct |
36 ms |
35960 KB |
Output is correct |
11 |
Correct |
37 ms |
35968 KB |
Output is correct |
12 |
Correct |
36 ms |
35968 KB |
Output is correct |
13 |
Correct |
36 ms |
35960 KB |
Output is correct |
14 |
Correct |
36 ms |
35968 KB |
Output is correct |
15 |
Correct |
39 ms |
35916 KB |
Output is correct |
16 |
Correct |
35 ms |
35960 KB |
Output is correct |
17 |
Correct |
40 ms |
35960 KB |
Output is correct |
18 |
Correct |
40 ms |
35968 KB |
Output is correct |
19 |
Correct |
43 ms |
35960 KB |
Output is correct |
20 |
Correct |
36 ms |
35968 KB |
Output is correct |
21 |
Correct |
37 ms |
35968 KB |
Output is correct |
22 |
Correct |
37 ms |
35968 KB |
Output is correct |
23 |
Correct |
36 ms |
35968 KB |
Output is correct |
24 |
Correct |
36 ms |
35968 KB |
Output is correct |
25 |
Correct |
37 ms |
35960 KB |
Output is correct |
26 |
Correct |
36 ms |
36088 KB |
Output is correct |
27 |
Correct |
179 ms |
37188 KB |
Output is correct |
28 |
Correct |
172 ms |
37112 KB |
Output is correct |
29 |
Correct |
178 ms |
37240 KB |
Output is correct |
30 |
Correct |
164 ms |
36984 KB |
Output is correct |
31 |
Correct |
156 ms |
37112 KB |
Output is correct |
32 |
Correct |
161 ms |
37240 KB |
Output is correct |
33 |
Correct |
163 ms |
37112 KB |
Output is correct |
34 |
Correct |
157 ms |
36856 KB |
Output is correct |
35 |
Correct |
127 ms |
37240 KB |
Output is correct |
36 |
Correct |
124 ms |
37240 KB |
Output is correct |
37 |
Correct |
119 ms |
37240 KB |
Output is correct |
38 |
Correct |
126 ms |
37240 KB |
Output is correct |
39 |
Correct |
125 ms |
37288 KB |
Output is correct |
40 |
Correct |
122 ms |
37368 KB |
Output is correct |
41 |
Correct |
116 ms |
37372 KB |
Output is correct |
42 |
Correct |
122 ms |
37368 KB |
Output is correct |
43 |
Correct |
119 ms |
37368 KB |
Output is correct |
44 |
Correct |
120 ms |
37368 KB |
Output is correct |
45 |
Correct |
115 ms |
37368 KB |
Output is correct |
46 |
Correct |
119 ms |
37368 KB |
Output is correct |
47 |
Correct |
120 ms |
37368 KB |
Output is correct |
48 |
Correct |
882 ms |
51192 KB |
Output is correct |
49 |
Correct |
876 ms |
51192 KB |
Output is correct |
50 |
Correct |
850 ms |
51168 KB |
Output is correct |
51 |
Correct |
875 ms |
50656 KB |
Output is correct |
52 |
Correct |
892 ms |
49400 KB |
Output is correct |
53 |
Correct |
869 ms |
50300 KB |
Output is correct |
54 |
Correct |
828 ms |
49400 KB |
Output is correct |
55 |
Correct |
854 ms |
49144 KB |
Output is correct |
56 |
Correct |
845 ms |
48888 KB |
Output is correct |
57 |
Execution timed out |
2592 ms |
81912 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |