100492024-03-25 20:09:59111Nemzetközi Rántott Hús Fesztiválcpp17Runtime error 0/100592ms359464 KiB
#include <bits/stdc++.h>
using namespace std;

// #define int long long

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin>>N;
	string S;
	cin>>S;
	vector<int>c(N+1),vk(N+1),vh(N+1),w(N+1),f(1);
	for(int i=0;i<N;i++){
		if(S[i]=='M'){
			f.push_back(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.push_back(N);
	vector<array<int,20>>tk(N+1),th(N+1);
	for(int i=0;i<N+1;i++){
		tk[i][0]=vk[i];
		th[i][0]=vh[i];
	}
	for(int j=1;j<20;j++){
		for(int l=0,r=1<<j-1;r<N+1;l++,r++){
			tk[l][j]=min(tk[l][j-1],tk[r][j-1]);
			th[l][j]=min(th[l][j-1],th[r][j-1]);
		}
	}
	auto qk=[&](int l,int r)->int{
		int i=__lg(r-l);
		return min(tk[l][i],tk[r-(1<<i)][i]);
	};
	auto qh=[&](int l,int r)->int{
		int i=__lg(r-l);
		return min(th[l][i],th[r-(1<<i)][i]);
	};
	return 1;
	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;
				}
			}
			cout<<c[N]-c[i]-(l-1)<<' ';
		}
		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;
				}
			}
			cout<<(l-1-i)/2<<' ';
		}
	}
	cout<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Runtime error3ms2104 KiB
2Runtime error4ms4064 KiB
subtask20/7
3Runtime error3ms2380 KiB
4Runtime error3ms2524 KiB
subtask30/9
5Runtime error4ms4472 KiB
6Runtime error3ms4712 KiB
7Runtime error4ms4928 KiB
subtask40/14
8Runtime error462ms349424 KiB
9Time limit exceeded592ms175880 KiB
10Time limit exceeded578ms176016 KiB
11Runtime error460ms349748 KiB
12Time limit exceeded549ms176252 KiB
13Runtime error453ms349836 KiB
14Time limit exceeded578ms176432 KiB
15Runtime error455ms349900 KiB
subtask50/11
16Runtime error3ms4004 KiB
17Runtime error3ms3808 KiB
18Runtime error3ms3832 KiB
subtask60/29
19Runtime error4ms5576 KiB
20Runtime error3ms5936 KiB
21Runtime error3ms5884 KiB
22Runtime error4ms6208 KiB
subtask70/30
23Time limit exceeded586ms178696 KiB
24Time limit exceeded583ms178808 KiB
25Time limit exceeded574ms178992 KiB
26Runtime error469ms355696 KiB
27Runtime error460ms356080 KiB
28Time limit exceeded550ms180072 KiB
29Runtime error465ms357204 KiB
30Time limit exceeded582ms179324 KiB
31Time limit exceeded579ms179708 KiB
32Runtime error460ms358172 KiB
33Time limit exceeded578ms181332 KiB
34Runtime error458ms359432 KiB
35Runtime error469ms359464 KiB
36Runtime error449ms350984 KiB
37Runtime error453ms351136 KiB
38Runtime error449ms351100 KiB
39Runtime error449ms350980 KiB
40Time limit exceeded574ms181804 KiB