-
Notifications
You must be signed in to change notification settings - Fork 0
/
F.cpp
68 lines (66 loc) · 1.26 KB
/
F.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
char s[maxn];
int dp[maxn];
int par[maxn];
int sub[maxn];
int opt[maxn];
int root(int x) {
if(par[x] == x) return x;
return par[x] = root(par[x]);
}
void join(int x, int y) {
x = root(x);
y = root(y);
if(x != y) {
if(sub[x] > sub[y]) swap(x, y);
par[x] = y;
sub[y] += sub[x];
opt[y] = max(opt[y], opt[x]);
}
}
int nextVal(int x) {
return opt[root(x)];
}
int ord[maxn];
int main() {
int n;
scanf("%d", &n);
scanf("%s", s + 1);
for(int i = 1; i <= n + 1; i++) {
par[i] = i;
sub[i] = 1;
opt[i] = i;
}
int cnt[] = {0, 0};
int r = n;
for(int i = n; i >= 1; i--) {
if(s[i] != '?') cnt[s[i] - '0'] += 1;
while(r > i && cnt[1] > 0 && cnt[0] > 0) {
if(s[r] != '?') cnt[s[r] - '0'] -= 1;
r -= 1;
}
dp[i] = r - i + 1;
ord[i] = i;
}
sort(ord + 1, ord + n + 1, [&] (int i, int j) {
return dp[i] < dp[j]; } );
int pt = 1;
for(int i = 1; i <= n; i++) {
while(pt <= n && dp[ord[pt]] < i) {
join(ord[pt], ord[pt] + 1);
++pt;
}
int ans = 0;
int cur = 1;
while(nextVal(cur) <= n) {
++ans;
cur = nextVal(cur);
cur += i;
}
printf("%d ", ans);
}
puts("");
return 0;
}