QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#422193#4986. 普勒亚wtc#60 86ms49296kbC++141.8kb2024-05-26 22:17:462024-05-26 22:17:47

Judging History

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

  • [2024-05-26 22:17:47]
  • 评测
  • 测评结果:60
  • 用时:86ms
  • 内存:49296kb
  • [2024-05-26 22:17:46]
  • 提交

answer

#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=(l);i<=(r);++i)
#define fd(i,l,r) for(int i=(l);i>=(r);--i)
#define fu(i,l,r) for(int i=(l);i<(r);++i)
#define ll long long
using namespace std;
const int N=100007;
int n,a[N],g[N];
char s[N];
int tot,to[N<<1],head[N<<1],nx[N<<1];
void add(int x,int y){nx[y]=head[x];head[x]=y;}
namespace tree{
	struct node{
		int ls,rs,s,mn;
	}t[N<<5];
	int rt[N],cnt;
	void upd(int l,int r,int &o,int x)
	{
		if(!o) o=++cnt;
		t[o].mn=a[x],t[o].s=1;
		if(l==r) return;
		int mid=l+r>>1;
		if(x<=mid) upd(l,mid,t[o].ls,x);
		else upd(mid+1,r,t[o].rs,x);
	}
	int calc(int o,int mn)
	{
		if(!o) return 0;
		if(!t[o].ls&&!t[o].rs) return mn<t[o].mn;
		if(mn<t[t[o].ls].mn) return t[o].s-t[t[o].ls].s+calc(t[o].ls,mn);
		return calc(t[o].rs,mn);
	}
	int merge(int x,int y)
	{
		if(!x||!y) return x+y;
		t[x].ls=merge(t[x].ls,t[y].ls);
		t[x].rs=merge(t[x].rs,t[y].rs);
		t[x].s=t[t[x].ls].s+calc(t[x].rs,t[t[x].ls].mn);
		t[x].mn=max(t[x].mn,t[y].mn);
		return x;
	}
}
using tree::rt;
using tree::upd;
using tree::merge;
int cnt=1,lt=1;
struct node{
	int len,f,c[26];
}t[N<<1];
void ins(int c)
{
	int p=lt,u=lt=++cnt;t[u].len=t[p].len+1;
	upd(1,n,rt[u],t[u].len);
	for(;p&&!t[p].c[c];p=t[p].f) t[p].c[c]=u;
	if(!p){t[u].f=1;return;}
	int q=t[p].c[c];
	if(t[q].len==t[p].len+1){t[u].f=q;return;}
	int v=++cnt;t[v]=t[q];
	t[v].len=t[p].len+1;t[u].f=t[q].f=v;
	for(;p&&t[p].c[c]==q;p=t[p].f) t[p].c[c]=v;
}
void dfs(int x)
{
	for(int i=head[x];i;i=nx[i])
		dfs(i),rt[x]=merge(rt[x],rt[i]);
	if(x>1)
	{
		int w=tree::t[rt[x]].s;
		g[t[x].len]+=w;g[t[t[x].f].len]-=w;
	}
}
int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	fo(i,1,n) scanf("%d",&a[i]);
	fo(i,1,n) ins(s[i]-'a');
	fo(i,2,cnt) add(t[i].f,i);
	dfs(1);
	fd(i,n,1) g[i]+=g[i+1];
	fo(i,1,n) printf("%d ",g[i]);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 1ms
memory: 4040kb

input:

acbbaabcbbaabaabbbbaaabcbabcaccabbaaaccbabacccbabbbcbcabbbabbacacbabccbacbaaabbaccacbbcbccbcacbaccac
68 23 71 12 36 58 63 45 66 70 89 13 58 3 77 67 9 29 31 78 85 77 58 25 33 16 16 75 30 21 88 10 11 85 70 13 39 40 94 7 80 69 36 78 94 90 95 69 25 38 80 57 80 83 61 70 2 35 57 52 14 57 55 48 67 4 15 69 ...

output:

11 31 53 68 85 93 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 

result:

ok 100 numbers

Test #2:

score: 20
Accepted
time: 1ms
memory: 3884kb

input:

pyypypypllyypllpyylpyppppylplylyyyllyplllyplyyppyllyplllylyyyyppppplllpyppypyllyyyypllpplpyyppppplyl
6489 12699 24452 25390 7084 9393 15186 18132 18638 23884 30910 25366 22450 25060 17009 15823 25943 4038 9105 3159 3394 8634 987 3917 26155 2531 10738 23443 14071 8934 14326 13465 30694 31823 22105 23...

output:

15 29 50 70 86 89 92 92 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 

result:

ok 100 numbers

Test #3:

score: 20
Accepted
time: 1ms
memory: 4032kb

input:

sivypusnsmldqevumxpgzsgvnvqiqnqarsteljbjoueplofavfeplsezjanzrzmyesmonwoxprqyifaxyflsgcingmonlpfamgho
824 8633 25470 16839 2516 24546 3657 32721 18866 4758 32384 30834 23868 21480 27132 15853 12867 11445 32560 10678 19952 6351 26812 8642 3325 5723 12096 17152 13348 17528 28014 5416 25816 21794 2660 1...

output:

46 94 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 

result:

ok 100 numbers

Test #4:

score: 20
Accepted
time: 1ms
memory: 3988kb

input:

dikckgegjllikcefjkffkkdkehkgljijlgddclelihfilhkchcgjjedlkdicljjedeggkedcdejfeeccecihhkllccikiddjkhdf
8532 4283 22131 21749 2077 18828 32692 3150 15868 13422 14546 5611 7047 24814 18227 1382 31354 17447 1174 25172 17835 22757 3751 27010 17728 2826 5328 29566 31519 29232 14419 9305 9126 8079 12950 186...

output:

30 84 96 96 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 

result:

ok 100 numbers

Subtask #2:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #5:

score: 20
Accepted
time: 5ms
memory: 5684kb

input:

gznnqpxkzmcgjxdgrbxtzvxvyjbxppmwgmsjoaarfhxkliuvethzkeqpvylstflsxebyobyzchpexvqdtdefzkfzxrxixhjbszfmrhhebvrjgqxruxjtifjyzvsoynsradgqeguhqbvqdfngmudhkwijwidmyjcxuwpadduiirjwtkydgfwdkkyrbsafnlwkgiojepgfqtjuunwggkaiihoecvlzeedpuzbulgufcpndklbyzbtavfizvntumsvfbzxseselpxcskarxgbactejwvgqvxkweaaocfqdgqfda...

output:

158 1802 4673 4989 4996 4995 4994 4993 4992 4991 4990 4989 4988 4987 4986 4985 4984 4983 4982 4981 4980 4979 4978 4977 4976 4975 4974 4973 4972 4971 4970 4969 4968 4967 4966 4965 4964 4963 4962 4961 4960 4959 4958 4957 4956 4955 4954 4953 4952 4951 4950 4949 4948 4947 4946 4945 4944 4943 4942 4941 4...

result:

ok 5000 numbers

Test #6:

score: 20
Accepted
time: 5ms
memory: 6092kb

input:

caacccbcccaaacbbbaccbaccacbaccbaabccacbaaacbcbbabbccaacbbbabbaacbbbaacabbaabcccbcaaacbabcbcccacbcbaccbcbacbacbcababacabbbabababccbbcacbcbaaacabcbcabbccacbabcbcbaabaabbcccaacbcbaabcacaaccbcaaccababababbacbbccccaccaccbacbbcbbbbaaccbabbaaaacabbbbbaaaaaaacaabbacbbbcbcbcccaaaabbbbcbcabcabcabcacaacbbbbabc...

output:

27 78 190 420 916 1825 3179 4207 4693 4877 4947 4971 4981 4985 4986 4985 4984 4983 4982 4981 4980 4979 4978 4977 4976 4975 4974 4973 4972 4971 4970 4969 4968 4967 4966 4965 4964 4963 4962 4961 4960 4959 4958 4957 4956 4955 4954 4953 4952 4951 4950 4949 4948 4947 4946 4945 4944 4943 4942 4941 4940 49...

result:

ok 5000 numbers

Test #7:

score: 20
Accepted
time: 3ms
memory: 6084kb

input:

ccaccbbcaabaaaaabaaccbaaaacbcacabaaaabbcbcabbbbcabcacbaacbbbbcabbcccccabcaaacbabcaccaaccbccbbccacaccbaaaaaaabcacbaabbabacabaccccacaacbaabbacccbaababbbcbbccbabbcacacbaabcccbbbcaabacccbbbbabaccbcbbacabaabbbcccabccccacacacbbacacbbcbbcbababcbcacacacbbbacabcaaccccccbbccccacbbaabababbcaacbccccaccbabcccccc...

output:

5000 4999 4998 4997 4996 4995 4994 4993 4992 4991 4990 4989 4988 4987 4986 4985 4984 4983 4982 4981 4980 4979 4978 4977 4976 4975 4974 4973 4972 4971 4970 4969 4968 4967 4966 4965 4964 4963 4962 4961 4960 4959 4958 4957 4956 4955 4954 4953 4952 4951 4950 4949 4948 4947 4946 4945 4944 4943 4942 4941 ...

result:

ok 5000 numbers

Test #8:

score: 20
Accepted
time: 4ms
memory: 6184kb

input:

wxwwwxwwxwxxwwxwxxxwwwwwwxwxxwxwwwwxxxwxwxxwwxwxwwwwwxxwxxxwxxwxwxxwxwwwwwwwwxxxxxwxxwwwwxwxxxwwxwwwxwwwxxwxxwwwwwxwwxxxxxxxwxwwxxxwwxwwwwxwwxxwxxwxwxwwxxwwxxxxxwwwwwwwxxxwxwwwwwwwwxwwxxwxwwxxwxxwxxxxxwwxwwxwwwxwwxxwwxwwwwwxxxxxxxwwxxxxwwwwxxxwxwxwwxwxxxwxwwwxwxwwxwwxwwxwxwwwxwxxxxwxwxwwxxwxwxxwwxxx...

output:

2 4 8 16 32 64 128 256 512 1017 1899 2931 3786 4364 4676 4833 4901 4937 4952 4960 4966 4969 4972 4973 4974 4975 4974 4973 4972 4971 4970 4969 4968 4967 4966 4965 4964 4963 4962 4961 4960 4959 4958 4957 4956 4955 4954 4953 4952 4951 4950 4949 4948 4947 4946 4945 4944 4943 4942 4941 4940 4939 4938 493...

result:

ok 5000 numbers

Subtask #3:

score: 20
Accepted

Test #9:

score: 20
Accepted
time: 84ms
memory: 49296kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

14 18 17 16 16 15 15 15 14 15 14 14 15 14 15 14 13 14 15 14 14 14 13 16 15 15 14 13 14 15 14 13 14 14 14 14 13 13 12 17 17 16 15 14 14 13 16 15 16 15 16 15 17 16 15 14 14 13 13 12 14 15 14 15 15 14 13 14 14 13 15 14 13 13 13 12 11 12 13 12 14 13 13 13 12 14 14 13 13 14 13 12 12 11 13 12 13 12 11 13 ...

result:

ok 100000 numbers

Test #10:

score: 20
Accepted
time: 86ms
memory: 49160kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

50001 50000 50000 49999 49999 49998 49998 49997 49997 49996 49996 49995 49995 49994 49994 49993 49993 49992 49992 49991 49991 49990 49990 49989 49989 49988 49988 49987 49987 49986 49986 49985 49985 49984 49984 49983 49983 49982 49982 49981 49981 49980 49980 49979 49979 49978 49978 49977 49977 49976 ...

result:

ok 100000 numbers

Test #11:

score: 20
Accepted
time: 84ms
memory: 49256kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951...

result:

ok 100000 numbers

Test #12:

score: 20
Accepted
time: 80ms
memory: 49108kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok 100000 numbers

Subtask #4:

score: 0
Runtime Error

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #13:

score: 0
Runtime Error

input:

yzyzyzyzyzzzyzzzzzyyzzyzzyyyzzzyyzzyyyyzyyzyzyzzzyyzyyyzzyyzzzzzzyyzzzzzzzyyzyyyzzyzyzzzzzyyzyzzzyyzzyzzyzzzzyzzzyyzzyzyzzyzyzzyyzzyzyyyzzyzzyyzyzyyzzyzzzyyzyzzzzzzyzzyzzzzyyyyzzyzzzyzyzyyzzzzyzzyzyyyyyzyzyzzyyyyyyzyzyyzyyyyzzzyyzyzzyyyyyzyyyyyyzyzyzyyyzzyzzzyzzzyzzzzyyzzzzyyyzyyyyyyyyyyzzyzyyzyyzyy...

output:


result: