QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#173489#5474. Incredibly Cute Penguin ChicksForever_Young#WA 190ms48300kbC++143.7kb2023-09-09 23:48:472023-09-09 23:48:48

Judging History

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

  • [2023-09-09 23:48:48]
  • 评测
  • 测评结果:WA
  • 用时:190ms
  • 内存:48300kb
  • [2023-09-09 23:48:47]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
using namespace std;
char ch[1000010];

const int MAX_NODE=3000030;
const int mo=998244353;

int son[MAX_NODE][2],fa[MAX_NODE],v[MAX_NODE],num[MAX_NODE],curNode;
LL sum[MAX_NODE];


//0 I>=C 1 I<C 2 I>=P 3 I<P 4 C>=P 5 C<P
int n,nm[3][1000010],rt[6][1000010],dp[1000010];

void sc(int x,int y,int w){son[x][w]=y; fa[y]=x;}
void rotate(int x){
	if (!x) return; int y=fa[x],w=son[y][1]==x;
	sc(y,son[x][w^1],w); sc(fa[y],x,son[fa[y]][1]==y); sc(x,y,w^1);
	
	sum[y]=sum[son[y][0]]+sum[son[y][1]]+num[y];
	sum[x]=sum[son[x][0]]+sum[son[x][1]]+num[x];
}
void splay(int x,int root=0){
	while (fa[x]!=root){
		int y=fa[x],w=son[y][1]==x;
		if (fa[y]!=root&&son[fa[y]][w]==y) rotate(y);
		rotate(x);
	}
}

int find(int wh,int ind,int x){
	//printf("find: %d %d %d\n",wh,ind,x);
	int tmp=rt[wh][ind],target=0;
	//printf("root: %d %d\n",tmp,v[tmp]);
	while (tmp){
		if (v[tmp]<x){
			target=tmp;
			tmp=son[tmp][1];
		}
		else tmp=son[tmp][0];
	}
	//printf("%d\n",target);
	if (target){
		splay(target);
		rt[wh][ind]=target;
	}
	return target;
}

void insert(int wh,int ind,int x,int y){
	//printf("insert: %d %d %d %d\n",wh,ind,x,y);
	if (rt[wh][ind]==0){
		rt[wh][ind]=++curNode;
		v[curNode]=x;
		num[curNode]=sum[curNode]=y;
	}
	else{
		int tmp=rt[wh][ind],tmp2;
		tmp=find(wh,ind,x);
		if (tmp==0){
			tmp=rt[wh][ind];
			while (son[tmp][0]) tmp=son[tmp][0];
			splay(tmp);
			if (v[tmp]!=x){
				son[tmp][0]=++curNode;
				fa[curNode]=tmp;
				v[curNode]=x;
				num[curNode]=sum[curNode]=y;
				sum[tmp]=sum[son[tmp][0]]+sum[son[tmp][1]]+num[tmp];
			}
			else{
				num[tmp]+=y;
				sum[tmp]+=y;
			}
			rt[wh][ind]=tmp;
		}
		else{
			tmp2=son[tmp][1];
			if (tmp2){
				while (son[tmp2][0]) tmp2=son[tmp2][0];
				splay(tmp2,tmp);
				if (v[tmp2]!=x){
					son[tmp][1]=++curNode;
					fa[curNode]=tmp;
					son[curNode][1]=tmp2;
					fa[tmp2]=curNode;
					
					v[curNode]=x;
					num[curNode]=y;
					sum[curNode]=y+sum[tmp2];
					sum[tmp]=sum[son[tmp][0]]+sum[son[tmp][1]]+num[tmp];
				}
				else{
					splay(tmp2);
					num[tmp2]+=y;
					sum[tmp2]+=y;
					tmp=tmp2;
				}
			}
			else{
				son[tmp][1]=++curNode;
				fa[curNode]=tmp;
				v[curNode]=x;
				num[curNode]=sum[curNode]=y;
				sum[tmp]=sum[son[tmp][0]]+sum[son[tmp][1]]+num[tmp];
			}
			rt[wh][ind]=tmp;
		}
	}
	//printf("root %d %d: %d\n",wh,ind,rt[wh][ind]);
	//printf("insert finish!\n");
}

LL check(int x,int y,int z,int ind){
	int o=(x+y-1)*2,p;
	if (nm[x][ind]>=nm[y][ind]) p=nm[x][ind]-nm[y][ind];
	else{
		o++;
		p=nm[y][ind]-nm[x][ind];
	}
	int tmp=find(o,p,nm[z][ind]-nm[x][ind]);
	//printf("%d %d %d %d %d\n",x,y,z,tmp,sum[son[tmp][0]]+num[tmp]);
	if (tmp) return sum[son[tmp][0]]+num[tmp];
	return 0;
}

void ins(int x,int y,int z,int ind){
	//printf("ins %d %d %d\n",x,y,z);
	int o=(x+y-1)*2,p;
	if (nm[x][ind]>=nm[y][ind]) p=nm[x][ind]-nm[y][ind];
	else{
		o++;
		p=nm[y][ind]-nm[x][ind];
	}
	insert(o,p,nm[z][ind]-nm[x][ind],dp[ind]);
}

int main(){
	//freopen("E.in","r",stdin);
	scanf("%s",ch+1);
	n=strlen(ch+1);
	
	
	for (int i=1;i<=n;i++){
		for (int j=0;j<3;j++) nm[j][i]=nm[j][i-1];
		if (ch[i]=='I') nm[0][i]++;
		else if (ch[i]=='C') nm[1][i]++;
		else if (ch[i]=='P') nm[2][i]++;
	}
	
	dp[0]=1;
	for (int j=0;j<2;j++)
		for (int k=j+1;k<3;k++)
			ins(j,k,3-j-k,0);
	
	for (int i=1;i<=n;i++){
		//printf("%d:\n",i);
		for (int j=0;j<2;j++)
			for (int k=j+1;k<3;k++)
				dp[i]=(dp[i]+check(j,k,3-j-k,i))%mo;
		for (int j=0;j<2;j++)
			for (int k=j+1;k<3;k++)
				ins(j,k,3-j-k,i);
		//printf("dp:%d\n",dp[i]);
	}
	
	printf("%d\n",dp[n]);
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 7912kb

input:

ICPC

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 2ms
memory: 10144kb

input:

CCCIIIPPP

output:

69

result:

ok single line: '69'

Test #3:

score: 0
Accepted
time: 0ms
memory: 10044kb

input:

PICCICCIPPI

output:

24

result:

ok single line: '24'

Test #4:

score: -100
Wrong Answer
time: 190ms
memory: 48300kb

input:

PCPPCCICPICPCPCPCCPPIPPPIICCCICPICCPPPIPCCCCICCIICPCCICCCPCICIPPIPIPIPPCCPCIPPCCPPCCIPPPIPPCIICIIIPPCIPPICPPICCPIICCCCCCCICPCCPPIPIPICPCIICPCCIPICCCPPCPIIICPCPPPIIIIICCCPCICCPPCPPCICIIIPIPICPCPPPPICPCPIPIIICCICPCIPPICCICPIIPPCCCIICPCPCCICCPICPPPPPPICCCIPCCICICIPICIIICCICPCIPIICPIPIIICCPCCIIPCCCCPIPI...

output:

696888869

result:

wrong answer 1st lines differ - expected: '216523282', found: '696888869'