QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#422186#4986. 普勒亚wtc#0 82ms52952kbC++141.8kb2024-05-26 22:00:182024-05-26 22:00:18

Judging History

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

  • [2024-05-26 22:00:18]
  • 评测
  • 测评结果:0
  • 用时:82ms
  • 内存:52952kb
  • [2024-05-26 22:00:18]
  • 提交

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);
		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: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 8092kb

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:

24 40 57 70 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:

wrong answer 1st numbers differ - expected: '11', found: '24'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 82ms
memory: 52952kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

48 144 107 50 139 48 138 844 48 138 53 137 836 138 1280 1279 25 839 1278 839 1277 1277 36 1277 833 837 126 36 105 138 124 36 124 124 137 261 47 141 19 137 138 124 49 48 172 36 827 47 825 49 257 49 1277 137 136 48 828 40 253 36 99 1270 118 1275 1275 121 47 133 827 133 1271 252 133 824 830 41 2 36 119...

result:

wrong answer 1st numbers differ - expected: '14', found: '48'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%