#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
#define all(x) (x).begin(),(x).end()
#define pb push_back
char *I;
int ri() {
int ret = 0;
while((*I<48 || *I>=58)) ++I;
while(!(*I<48 || *I>=58)) ret=ret*10+(*I)-48,++I;
return ret;
}
void read(int& x){ x = ri(); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
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);
}
}
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
int main()
{
{ struct stat Z; fstat(0, &Z); I=(char*)mmap(0,Z.st_size,1,2,0,0); }
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:47:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
47 | for(auto& v:adj) v.clear(); memset(self, 0, sizeof(self)); memset(t, 0, sizeof(t));
| ^~~
rope.cpp:47:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
47 | for(auto& v:adj) v.clear(); memset(self, 0, sizeof(self)); memset(t, 0, sizeof(t));
| ^~~~~~
rope.cpp: In function 'void Do2()':
rope.cpp:74:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
74 | for(auto& v:adj) v.clear(); memset(self, 0, sizeof(self)); memset(t, 0, sizeof(t));
| ^~~
rope.cpp:74:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
74 | for(auto& v:adj) v.clear(); memset(self, 0, sizeof(self)); memset(t, 0, sizeof(t));
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
35964 KB |
Output is correct |
2 |
Correct |
40 ms |
35964 KB |
Output is correct |
3 |
Correct |
37 ms |
35964 KB |
Output is correct |
4 |
Correct |
37 ms |
35964 KB |
Output is correct |
5 |
Correct |
37 ms |
36084 KB |
Output is correct |
6 |
Correct |
37 ms |
35964 KB |
Output is correct |
7 |
Correct |
37 ms |
35964 KB |
Output is correct |
8 |
Correct |
37 ms |
35956 KB |
Output is correct |
9 |
Correct |
38 ms |
35964 KB |
Output is correct |
10 |
Correct |
38 ms |
36060 KB |
Output is correct |
11 |
Correct |
38 ms |
35964 KB |
Output is correct |
12 |
Correct |
37 ms |
35964 KB |
Output is correct |
13 |
Correct |
36 ms |
35956 KB |
Output is correct |
14 |
Correct |
36 ms |
35956 KB |
Output is correct |
15 |
Correct |
37 ms |
35964 KB |
Output is correct |
16 |
Correct |
37 ms |
35964 KB |
Output is correct |
17 |
Correct |
37 ms |
36084 KB |
Output is correct |
18 |
Correct |
37 ms |
35964 KB |
Output is correct |
19 |
Correct |
36 ms |
35964 KB |
Output is correct |
20 |
Correct |
37 ms |
35996 KB |
Output is correct |
21 |
Correct |
37 ms |
35960 KB |
Output is correct |
22 |
Correct |
38 ms |
35964 KB |
Output is correct |
23 |
Correct |
37 ms |
35964 KB |
Output is correct |
24 |
Correct |
36 ms |
35964 KB |
Output is correct |
25 |
Correct |
37 ms |
35956 KB |
Output is correct |
26 |
Correct |
37 ms |
35964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
35964 KB |
Output is correct |
2 |
Correct |
40 ms |
35964 KB |
Output is correct |
3 |
Correct |
37 ms |
35964 KB |
Output is correct |
4 |
Correct |
37 ms |
35964 KB |
Output is correct |
5 |
Correct |
37 ms |
36084 KB |
Output is correct |
6 |
Correct |
37 ms |
35964 KB |
Output is correct |
7 |
Correct |
37 ms |
35964 KB |
Output is correct |
8 |
Correct |
37 ms |
35956 KB |
Output is correct |
9 |
Correct |
38 ms |
35964 KB |
Output is correct |
10 |
Correct |
38 ms |
36060 KB |
Output is correct |
11 |
Correct |
38 ms |
35964 KB |
Output is correct |
12 |
Correct |
37 ms |
35964 KB |
Output is correct |
13 |
Correct |
36 ms |
35956 KB |
Output is correct |
14 |
Correct |
36 ms |
35956 KB |
Output is correct |
15 |
Correct |
37 ms |
35964 KB |
Output is correct |
16 |
Correct |
37 ms |
35964 KB |
Output is correct |
17 |
Correct |
37 ms |
36084 KB |
Output is correct |
18 |
Correct |
37 ms |
35964 KB |
Output is correct |
19 |
Correct |
36 ms |
35964 KB |
Output is correct |
20 |
Correct |
37 ms |
35996 KB |
Output is correct |
21 |
Correct |
37 ms |
35960 KB |
Output is correct |
22 |
Correct |
38 ms |
35964 KB |
Output is correct |
23 |
Correct |
37 ms |
35964 KB |
Output is correct |
24 |
Correct |
36 ms |
35964 KB |
Output is correct |
25 |
Correct |
37 ms |
35956 KB |
Output is correct |
26 |
Correct |
37 ms |
35964 KB |
Output is correct |
27 |
Correct |
145 ms |
37192 KB |
Output is correct |
28 |
Correct |
138 ms |
37108 KB |
Output is correct |
29 |
Correct |
143 ms |
37236 KB |
Output is correct |
30 |
Correct |
142 ms |
36904 KB |
Output is correct |
31 |
Correct |
143 ms |
37116 KB |
Output is correct |
32 |
Correct |
138 ms |
37128 KB |
Output is correct |
33 |
Correct |
144 ms |
37108 KB |
Output is correct |
34 |
Correct |
145 ms |
36980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
35964 KB |
Output is correct |
2 |
Correct |
40 ms |
35964 KB |
Output is correct |
3 |
Correct |
37 ms |
35964 KB |
Output is correct |
4 |
Correct |
37 ms |
35964 KB |
Output is correct |
5 |
Correct |
37 ms |
36084 KB |
Output is correct |
6 |
Correct |
37 ms |
35964 KB |
Output is correct |
7 |
Correct |
37 ms |
35964 KB |
Output is correct |
8 |
Correct |
37 ms |
35956 KB |
Output is correct |
9 |
Correct |
38 ms |
35964 KB |
Output is correct |
10 |
Correct |
38 ms |
36060 KB |
Output is correct |
11 |
Correct |
38 ms |
35964 KB |
Output is correct |
12 |
Correct |
37 ms |
35964 KB |
Output is correct |
13 |
Correct |
36 ms |
35956 KB |
Output is correct |
14 |
Correct |
36 ms |
35956 KB |
Output is correct |
15 |
Correct |
37 ms |
35964 KB |
Output is correct |
16 |
Correct |
37 ms |
35964 KB |
Output is correct |
17 |
Correct |
37 ms |
36084 KB |
Output is correct |
18 |
Correct |
37 ms |
35964 KB |
Output is correct |
19 |
Correct |
36 ms |
35964 KB |
Output is correct |
20 |
Correct |
37 ms |
35996 KB |
Output is correct |
21 |
Correct |
37 ms |
35960 KB |
Output is correct |
22 |
Correct |
38 ms |
35964 KB |
Output is correct |
23 |
Correct |
37 ms |
35964 KB |
Output is correct |
24 |
Correct |
36 ms |
35964 KB |
Output is correct |
25 |
Correct |
37 ms |
35956 KB |
Output is correct |
26 |
Correct |
37 ms |
35964 KB |
Output is correct |
27 |
Correct |
145 ms |
37192 KB |
Output is correct |
28 |
Correct |
138 ms |
37108 KB |
Output is correct |
29 |
Correct |
143 ms |
37236 KB |
Output is correct |
30 |
Correct |
142 ms |
36904 KB |
Output is correct |
31 |
Correct |
143 ms |
37116 KB |
Output is correct |
32 |
Correct |
138 ms |
37128 KB |
Output is correct |
33 |
Correct |
144 ms |
37108 KB |
Output is correct |
34 |
Correct |
145 ms |
36980 KB |
Output is correct |
35 |
Correct |
118 ms |
37324 KB |
Output is correct |
36 |
Correct |
117 ms |
37364 KB |
Output is correct |
37 |
Correct |
117 ms |
37320 KB |
Output is correct |
38 |
Correct |
117 ms |
37492 KB |
Output is correct |
39 |
Correct |
117 ms |
37368 KB |
Output is correct |
40 |
Correct |
118 ms |
37368 KB |
Output is correct |
41 |
Correct |
117 ms |
37372 KB |
Output is correct |
42 |
Correct |
117 ms |
37364 KB |
Output is correct |
43 |
Correct |
119 ms |
37372 KB |
Output is correct |
44 |
Correct |
118 ms |
37364 KB |
Output is correct |
45 |
Correct |
117 ms |
37364 KB |
Output is correct |
46 |
Correct |
117 ms |
37364 KB |
Output is correct |
47 |
Correct |
118 ms |
37372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
35964 KB |
Output is correct |
2 |
Correct |
40 ms |
35964 KB |
Output is correct |
3 |
Correct |
37 ms |
35964 KB |
Output is correct |
4 |
Correct |
37 ms |
35964 KB |
Output is correct |
5 |
Correct |
37 ms |
36084 KB |
Output is correct |
6 |
Correct |
37 ms |
35964 KB |
Output is correct |
7 |
Correct |
37 ms |
35964 KB |
Output is correct |
8 |
Correct |
37 ms |
35956 KB |
Output is correct |
9 |
Correct |
38 ms |
35964 KB |
Output is correct |
10 |
Correct |
38 ms |
36060 KB |
Output is correct |
11 |
Correct |
38 ms |
35964 KB |
Output is correct |
12 |
Correct |
37 ms |
35964 KB |
Output is correct |
13 |
Correct |
36 ms |
35956 KB |
Output is correct |
14 |
Correct |
36 ms |
35956 KB |
Output is correct |
15 |
Correct |
37 ms |
35964 KB |
Output is correct |
16 |
Correct |
37 ms |
35964 KB |
Output is correct |
17 |
Correct |
37 ms |
36084 KB |
Output is correct |
18 |
Correct |
37 ms |
35964 KB |
Output is correct |
19 |
Correct |
36 ms |
35964 KB |
Output is correct |
20 |
Correct |
37 ms |
35996 KB |
Output is correct |
21 |
Correct |
37 ms |
35960 KB |
Output is correct |
22 |
Correct |
38 ms |
35964 KB |
Output is correct |
23 |
Correct |
37 ms |
35964 KB |
Output is correct |
24 |
Correct |
36 ms |
35964 KB |
Output is correct |
25 |
Correct |
37 ms |
35956 KB |
Output is correct |
26 |
Correct |
37 ms |
35964 KB |
Output is correct |
27 |
Correct |
145 ms |
37192 KB |
Output is correct |
28 |
Correct |
138 ms |
37108 KB |
Output is correct |
29 |
Correct |
143 ms |
37236 KB |
Output is correct |
30 |
Correct |
142 ms |
36904 KB |
Output is correct |
31 |
Correct |
143 ms |
37116 KB |
Output is correct |
32 |
Correct |
138 ms |
37128 KB |
Output is correct |
33 |
Correct |
144 ms |
37108 KB |
Output is correct |
34 |
Correct |
145 ms |
36980 KB |
Output is correct |
35 |
Correct |
118 ms |
37324 KB |
Output is correct |
36 |
Correct |
117 ms |
37364 KB |
Output is correct |
37 |
Correct |
117 ms |
37320 KB |
Output is correct |
38 |
Correct |
117 ms |
37492 KB |
Output is correct |
39 |
Correct |
117 ms |
37368 KB |
Output is correct |
40 |
Correct |
118 ms |
37368 KB |
Output is correct |
41 |
Correct |
117 ms |
37372 KB |
Output is correct |
42 |
Correct |
117 ms |
37364 KB |
Output is correct |
43 |
Correct |
119 ms |
37372 KB |
Output is correct |
44 |
Correct |
118 ms |
37364 KB |
Output is correct |
45 |
Correct |
117 ms |
37364 KB |
Output is correct |
46 |
Correct |
117 ms |
37364 KB |
Output is correct |
47 |
Correct |
118 ms |
37372 KB |
Output is correct |
48 |
Correct |
854 ms |
51188 KB |
Output is correct |
49 |
Correct |
850 ms |
51188 KB |
Output is correct |
50 |
Correct |
854 ms |
51060 KB |
Output is correct |
51 |
Correct |
837 ms |
50736 KB |
Output is correct |
52 |
Correct |
830 ms |
49428 KB |
Output is correct |
53 |
Correct |
835 ms |
50420 KB |
Output is correct |
54 |
Correct |
836 ms |
49268 KB |
Output is correct |
55 |
Correct |
817 ms |
49132 KB |
Output is correct |
56 |
Correct |
826 ms |
48888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
35964 KB |
Output is correct |
2 |
Correct |
40 ms |
35964 KB |
Output is correct |
3 |
Correct |
37 ms |
35964 KB |
Output is correct |
4 |
Correct |
37 ms |
35964 KB |
Output is correct |
5 |
Correct |
37 ms |
36084 KB |
Output is correct |
6 |
Correct |
37 ms |
35964 KB |
Output is correct |
7 |
Correct |
37 ms |
35964 KB |
Output is correct |
8 |
Correct |
37 ms |
35956 KB |
Output is correct |
9 |
Correct |
38 ms |
35964 KB |
Output is correct |
10 |
Correct |
38 ms |
36060 KB |
Output is correct |
11 |
Correct |
38 ms |
35964 KB |
Output is correct |
12 |
Correct |
37 ms |
35964 KB |
Output is correct |
13 |
Correct |
36 ms |
35956 KB |
Output is correct |
14 |
Correct |
36 ms |
35956 KB |
Output is correct |
15 |
Correct |
37 ms |
35964 KB |
Output is correct |
16 |
Correct |
37 ms |
35964 KB |
Output is correct |
17 |
Correct |
37 ms |
36084 KB |
Output is correct |
18 |
Correct |
37 ms |
35964 KB |
Output is correct |
19 |
Correct |
36 ms |
35964 KB |
Output is correct |
20 |
Correct |
37 ms |
35996 KB |
Output is correct |
21 |
Correct |
37 ms |
35960 KB |
Output is correct |
22 |
Correct |
38 ms |
35964 KB |
Output is correct |
23 |
Correct |
37 ms |
35964 KB |
Output is correct |
24 |
Correct |
36 ms |
35964 KB |
Output is correct |
25 |
Correct |
37 ms |
35956 KB |
Output is correct |
26 |
Correct |
37 ms |
35964 KB |
Output is correct |
27 |
Correct |
145 ms |
37192 KB |
Output is correct |
28 |
Correct |
138 ms |
37108 KB |
Output is correct |
29 |
Correct |
143 ms |
37236 KB |
Output is correct |
30 |
Correct |
142 ms |
36904 KB |
Output is correct |
31 |
Correct |
143 ms |
37116 KB |
Output is correct |
32 |
Correct |
138 ms |
37128 KB |
Output is correct |
33 |
Correct |
144 ms |
37108 KB |
Output is correct |
34 |
Correct |
145 ms |
36980 KB |
Output is correct |
35 |
Correct |
118 ms |
37324 KB |
Output is correct |
36 |
Correct |
117 ms |
37364 KB |
Output is correct |
37 |
Correct |
117 ms |
37320 KB |
Output is correct |
38 |
Correct |
117 ms |
37492 KB |
Output is correct |
39 |
Correct |
117 ms |
37368 KB |
Output is correct |
40 |
Correct |
118 ms |
37368 KB |
Output is correct |
41 |
Correct |
117 ms |
37372 KB |
Output is correct |
42 |
Correct |
117 ms |
37364 KB |
Output is correct |
43 |
Correct |
119 ms |
37372 KB |
Output is correct |
44 |
Correct |
118 ms |
37364 KB |
Output is correct |
45 |
Correct |
117 ms |
37364 KB |
Output is correct |
46 |
Correct |
117 ms |
37364 KB |
Output is correct |
47 |
Correct |
118 ms |
37372 KB |
Output is correct |
48 |
Correct |
854 ms |
51188 KB |
Output is correct |
49 |
Correct |
850 ms |
51188 KB |
Output is correct |
50 |
Correct |
854 ms |
51060 KB |
Output is correct |
51 |
Correct |
837 ms |
50736 KB |
Output is correct |
52 |
Correct |
830 ms |
49428 KB |
Output is correct |
53 |
Correct |
835 ms |
50420 KB |
Output is correct |
54 |
Correct |
836 ms |
49268 KB |
Output is correct |
55 |
Correct |
817 ms |
49132 KB |
Output is correct |
56 |
Correct |
826 ms |
48888 KB |
Output is correct |
57 |
Execution timed out |
2593 ms |
80352 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |