QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#214859#5474. Incredibly Cute Penguin ChickswxhtzdyRE 0ms0kbC++142.4kb2023-10-15 00:37:262023-10-15 00:37:26

Judging History

你现在查看的是最新测评结果

  • [2023-10-15 00:37:26]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-10-15 00:37:26]
  • 提交

answer

#include<bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int cys=998244353;

int mod(int x){return x%cys;}

int n,a[1000005],pref[4][1000005][2],dp[1000005],g[4][1000005],v[4][1000005];
char s[1000005];

struct f{
	vector<int> fnw;
	int n;
	f(){n=0;fnw.clear();}
	void set_size(int x){
		n=x; fnw.resize(x+1);
	}
	void change(int p,int v){
		for(++p;p<=n;p+=p&-p) fnw[p]=mod(fnw[p]+v);
	}
	int query(int p){
		int ret=0;
		for(p++;p>0;p-=p&-p) ret=mod(ret+fnw[p]);
		return ret;
	}
}fenw[4][1000005];

int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++) a[i]=(s[i]=='C'?1:(s[i]=='I'?2:3));
	for(int mx=1;mx<=3;mx++){
		int x,y;
		if(mx==1) x=2,y=3;
		if(mx==2) x=3,y=1;
		if(mx==3) x=1,y=2;
		for(int i=1;i<=n;i++){
			pref[mx][i][0]=pref[mx][i-1][0];
			if(a[i]==x) pref[mx][i][0]++;
			if(a[i]==y) pref[mx][i][0]--;
		}
		vector<int> xs;
		for(int i=0;i<=n;i++) xs.pb(pref[mx][i][0]);
		sort(xs.begin(),xs.end());
		xs.erase(unique(xs.begin(),xs.end()),xs.end());
		for(int i=0;i<=n;i++) 
			g[mx][i]=(int)(lower_bound(xs.begin(),xs.end(),pref[mx][i][0])-xs.begin());
		for(int i=1;i<=n;i++){
			pref[mx][i][1]=pref[mx][i-1][1];
			if(a[i]==mx) pref[mx][i][1]+=2;
			if(a[i]!=mx) pref[mx][i][1]-=1;
		}
		map<int,vector<int>> ids;
		for(int i=0;i<=n;i++){
			ids[pref[mx][i][0]].pb(i);
		}
		for(auto&p:ids){
			xs.clear();
			xs.pb(-3000000);
			for(int i:p.se) xs.pb(pref[mx][i][1]);
			sort(xs.begin(),xs.end());
			xs.erase(unique(xs.begin(),xs.end()));
			for(int i:p.se)
				v[mx][i]=(int)(lower_bound(xs.begin(),xs.end(),pref[mx][i][1])-xs.begin());
			fenw[mx][g[mx][p.se[0]]].set_size(xs.size());
		}
	}
	dp[0]=1;
	for(int i=0;i<=n;i++){
		for(int mx=1;mx<=3;mx++){
			int val=fenw[mx][g[mx][i]].query(v[mx][i]-1);
			dp[i]=mod(dp[i]+val);
		}
		for(int mx=1;mx<=3;mx++){
			fenw[mx][g[mx][i]].change(v[mx][i],dp[i]);
		}
	}
	printf("%d\n",dp[n]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

ICPC

output:


result: