QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#882#582757#6624. String ProblemSoestxSoestxFailed.2024-09-22 17:30:372024-09-22 17:30:38

詳細信息

Extra Test:

Invalid Input

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:


result:

FAIL Token parameter [name=str] equals to "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", doesn't correspond to pattern "[a-z]{1,1000000}" (stdin, line 1)

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#582757#6624. String ProblemSoestxAC ✓535ms12940kbC++141.5kb2024-09-22 17:23:252024-09-22 17:23:33

answer

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fi first
#define se second
#define lowbit(x) x&(-x)
#define pll pair<int,int>
typedef long long ll;
//typedef unsigned long long ull;
const int N=1e6+10,M=1e6,mod=998244353;
int n,m,k;
int num[N];
int res;

string s;
int ne[N],len=0,j=0;
int be;
void ini(char c)
{
	s="x";
	s+=c;
	len=1;
	j=0;
	ne[1]=0;
	be=0;
}

void add(char c)
{
	s+=c;
	//cout<<s<<endl;
	len++;
	while(j&&s[j+1]!=s[len]) j=ne[j];
	if(s[j+1]==c)
	{
		if(!be) be=len;
		//cout<<s<<" "<<s[j+1]<<" "<<s[len]<<endl;
		j++;
	}
	ne[len]=j;
}

void to(int l)
{
	s=s.substr(0,l+1);
	len=l;
	j=ne[l];
	if(be>l) be=0;
	//cout<<"TO _----"<<l<<" "<<j<<endl;
	//for(int i=1;i<=l;i++) cout<<ne[i]<<" ";cout<<endl;
}

void solve()
{
	string s;
	cin>>s;
	n=s.size();
	s='a'+s;
	ini(s[1]);
	int L=1;
	//for(int j=1;j<=len;j++) cout<<ne[j]<<" ";cout<<endl;
	cout<<"1 1"<<endl;
	for(int i=2;i<=n;i++)
	{
		if(s[i]>s[L]) L=i,ini(s[i]);
		else
		{
			int idx=-1;
			int p=len;
			while(p>1)
			{
				if(ne[p]==len-1) break;
				if(s[L+ne[p]]<s[i]) idx=ne[p];
				p=ne[p];
			}
			if(idx!=-1) L=i-idx,to(idx);
			add(s[i]);
		}
		cout<<L<<" "<<i<<endl;
		//cout<<i<<"-"<<j<<endl;
		//for(int j=1;j<=len;j++) cout<<ne[j]<<" ";cout<<endl;
	}
}

signed main()
{
	//ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T;
	T=1;
	//cin>>T;
	while(T--) solve();
	return 0;
}
/*
gtgggtgttgggggt gtgggtgttggttt
ccccccccccccccccccc
*/