10060 | 2024-03-25 20:47:48 | 111 | Nemzetközi Rántott Hús Fesztivál | cpp17 | Accepted 100/100 | 465ms | 362888 KiB |
#include <bits/stdc++.h>
using namespace std;
// #define int long long
char bf[11000000];
int bfp=0;
void wc(char c) {
bf[bfp++] = c;
}
void wu(int i) {
int x = 1;
int c = 1;
while (x <= i / 10) {
x *= 10;
c++;
}
while (c--) {
int d = i / x;
wc('0' + d);
i -= d * x;
i *= 10;
}
}
#define MN 1000002
alignas(64) int c[MN],vk[MN],vh[MN],w[MN],f[MN],fe,tk[20][MN],th[20][MN];
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin>>N;
string S;
cin>>S;
f[fe++]=1;
for(int i=0;i<N;i++){
if(S[i]=='M'){
f[fe++]=i;
}
c[i+1]=c[i]+(S[i]!='K');
vk[i+1]=(S[i]!='H'?vk[i]+1:vk[i]-1);
vh[i+1]=(S[i]!='K'?vh[i]-1:vh[i]+1);
w[i+1]=w[i]+(S[i]=='M');
}
f[fe++]=N;
for(int i=0;i<N+1;i++){
tk[0][i]=vk[i];
th[0][i]=vh[i];
}
for(int j=1;j<20;j++){
for(int l=0,r=1<<j-1;r<N+1;l++,r++){
tk[j][l]=min(tk[j-1][l],tk[j-1][r]);
th[j][l]=min(th[j-1][l],th[j-1][r]);
}
}
auto qk=[&](int l,int r)->int{
int i=__lg(r-l);
return min(tk[i][l],tk[i][r-(1<<i)]);
};
auto qh=[&](int l,int r)->int{
int i=__lg(r-l);
return min(th[i][l],th[i][r-(1<<i)]);
};
for(int i=0;i<N;i++){
int b=qk(i+1,N+1)-vk[i]>=0;
if(b){
int l=1,h=w[N]-w[i]+1;
while(l<h){
int m=(l+h)/2;
int j=f[w[i]+m];
int x=vk[j]-vk[i];
if(qh(j,N+1)-vh[j]+x>=0){
h=m;
}
else{
l=m+1;
}
}
wu(c[N]-c[i]-(l-1));wc(' ');
}
else{
int l=i+1,h=N;
while(l<h){
int m=(l+h)/2;
if(qk(i+1,m+1)-vk[i]>=0){
l=m+1;
}
else{
h=m;
}
}
wu((l-1-i)/2);wc(' ');
}
}
wc('\n');
fwrite(bf,sizeof(char),bfp,stdout);
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 2024 KiB | ||||
2 | Accepted | 4ms | 3680 KiB | ||||
subtask2 | 7/7 | ||||||
3 | Accepted | 3ms | 2336 KiB | ||||
4 | Accepted | 3ms | 2564 KiB | ||||
subtask3 | 9/9 | ||||||
5 | Accepted | 4ms | 4068 KiB | ||||
6 | Accepted | 4ms | 4284 KiB | ||||
7 | Accepted | 4ms | 4424 KiB | ||||
subtask4 | 14/14 | ||||||
8 | Accepted | 379ms | 345504 KiB | ||||
9 | Accepted | 358ms | 346464 KiB | ||||
10 | Accepted | 358ms | 346420 KiB | ||||
11 | Accepted | 360ms | 346120 KiB | ||||
12 | Accepted | 326ms | 350016 KiB | ||||
13 | Accepted | 270ms | 351568 KiB | ||||
14 | Accepted | 324ms | 347464 KiB | ||||
15 | Accepted | 375ms | 346940 KiB | ||||
subtask5 | 11/11 | ||||||
16 | Accepted | 3ms | 3800 KiB | ||||
17 | Accepted | 3ms | 3748 KiB | ||||
18 | Accepted | 3ms | 3872 KiB | ||||
subtask6 | 29/29 | ||||||
19 | Accepted | 4ms | 5200 KiB | ||||
20 | Accepted | 4ms | 5188 KiB | ||||
21 | Accepted | 4ms | 5200 KiB | ||||
22 | Accepted | 4ms | 5344 KiB | ||||
subtask7 | 30/30 | ||||||
23 | Accepted | 458ms | 353000 KiB | ||||
24 | Accepted | 462ms | 353008 KiB | ||||
25 | Accepted | 458ms | 352988 KiB | ||||
26 | Accepted | 465ms | 355756 KiB | ||||
27 | Accepted | 460ms | 357324 KiB | ||||
28 | Accepted | 458ms | 358332 KiB | ||||
29 | Accepted | 451ms | 358944 KiB | ||||
30 | Accepted | 460ms | 355732 KiB | ||||
31 | Accepted | 458ms | 357164 KiB | ||||
32 | Accepted | 435ms | 360548 KiB | ||||
33 | Accepted | 409ms | 361700 KiB | ||||
34 | Accepted | 361ms | 362576 KiB | ||||
35 | Accepted | 340ms | 362664 KiB | ||||
36 | Accepted | 293ms | 350360 KiB | ||||
37 | Accepted | 266ms | 351948 KiB | ||||
38 | Accepted | 324ms | 347880 KiB | ||||
39 | Accepted | 409ms | 347516 KiB | ||||
40 | Accepted | 375ms | 362888 KiB |