QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#560831#8223. 字符串游戏syp110 113ms181944kbC++141.6kb2024-09-12 18:13:382024-09-12 18:13:39

Judging History

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

  • [2024-09-12 18:13:39]
  • 评测
  • 测评结果:0
  • 用时:113ms
  • 内存:181944kb
  • [2024-09-12 18:13:38]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e6+10;
int n,lst=1,tot=1,cnt,fa[N],len[N],id[N],pi[N],po[N],tr[N],f[N][21],ch[N][26],dp[N];
string s;
vector<int>a[N];
void insert(int c,int i)
{
	int p=lst;
	int u=++tot;
	len[lst=id[i]=u]=len[p]+1;
	while(p&&!ch[p][c])
	{
		ch[p][c]=u;
		p=fa[p];
	}
	if(!p)
	{
		fa[u]=1;
		return;
	}
	int q=ch[p][c];
	if(len[p]+1==len[q])
	{
		fa[u]=q;
		return;
	}
	int nq=++tot;
	copy_n(ch[q],26,ch[nq]);
	fa[nq]=fa[q];
	len[nq]=len[p]+1;
	fa[u]=fa[q]=nq;
	while(p&&ch[p][c]==q)
	{
		ch[p][c]=nq;
		p=fa[p];
	}
	return;
}
void dfs(int x)
{
	pi[x]=++cnt;
	f[x][0]=fa[x];
	for(int i=1;i<21;i++)
	{
		f[x][i]=f[f[x][i-1]][i-1];
	}
	for(auto y:a[x])
	{
		dfs(y);
	}
	po[x]=cnt;
	return;
}
int ask(int x)
{
	int res=0;
	for(;x;x-=x&-x)
	{
		res+=tr[x];
	}
	return res;
}
int occ(int l,int r)
{
	int u=id[r];
	for(int i=20;~i;i--)
	{
		if(f[u][i]&&len[f[u][i]]>r-l)
		{
			u=f[u][i];
		}
	}
	return ask(po[u])-ask(pi[u]-1);
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>s;
	n=s.size();
	for(int i=1;i<=n;i++)
	{
		insert(s[n-i]-'a',i);
	}
	for(int i=2;i<=tot;i++)
	{
		a[fa[i]].push_back(i);
	}
	dfs(1);
	stack<int>st;
	for(int i=1;i<=n;i++)
	{
		for(int x=pi[id[i]];x<=tot;x+=x&-x)
		{
			tr[x]++;
		}
		dp[i]=1;
		while(!st.empty())
		{
			int j=st.top();
			st.pop();
			dp[i]=max(dp[i],occ(j+1,i)-dp[j]);
			if(dp[i]>dp[j])
			{
				break;
			}
		}
		st.push(i);
	}
	cout<<dp[n]<<flush;
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 68240kb

input:

abbabbbbabbaaaaabbbaabaaaaaabbbaabbabababaabababaababaaaaaabaaabaaabbbbababaaabbbabababbbabbbaabaaababbbaabaabbaaabbababaaaaabbbaabaaabbaabaabaaabaaabaababaabbbbbbbbabbbbbabbbaabababbaababbbbbabbbbaaabbaabaabaaabbabbaaabbaaababaabbbaabbbaaaabbababbabaababababaaaabbaaaabaabaaaababaaabababbbaaabababbb...

output:

1512

result:

wrong answer 1st lines differ - expected: '1281', found: '1512'

Subtask #2:

score: 0
Memory Limit Exceeded

Test #11:

score: 0
Memory Limit Exceeded

input:

aaaaaaabbaaabbbbabbabbbababaabaaabaabbaaababaaaaaabbbbbaabbbabbbaabbabaababaababaabbbababbbabaaaaaaaaabaaaaabbbabbbbbabaaabaaaababbabbbbbbaabbbbbaababbbbababbbbbbbbbbbaaabbabbaababbaaaabbabaaabbaaabbbbaaababbbbbabbaababbaaababaaabbabaabbbbabbaaabbababbaabbaaaaaaaaaabababbbaaaababbabbbabbababbabbabbb...

output:

357869

result:


Subtask #3:

score: 0
Memory Limit Exceeded

Test #16:

score: 0
Memory Limit Exceeded

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

493827

result:


Subtask #4:

score: 0
Wrong Answer

Test #17:

score: 0
Wrong Answer
time: 113ms
memory: 181944kb

input:

bbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbabaabaaabbabbaaababaaabaaaabababbbbbbbaabbaaabbabbbbbabbbaaaaababbbaaabaabababbabbabababbabbabaaaaabaaaaaabbbabaabbbaaaabbabababaaababaabbbbbbbaaabbbabaabaaaabaabaababbaaaabababaabbbaaaababaaababbbbbbabbbbbbaabbabbaaa...

output:

41479

result:

wrong answer 1st lines differ - expected: '43524', found: '41479'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #2:

0%