QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#582582#6624. String ProblemSoestxTL 3ms5880kbC++141.2kb2024-09-22 16:53:202024-09-22 16:53:22

Judging History

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

  • [2024-09-22 16:53:22]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:5880kb
  • [2024-09-22 16:53:20]
  • 提交

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;

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

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

void to(int l)
{
	len=l;
	j=ne[l];
}

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(s[L+ne[p]]<s[i]) idx=ne[p];
				p=ne[p];
			}
			if(idx!=-1) L=i-p,to(p);
			add(s[i]);
		}
		cout<<L<<" "<<i<<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;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5584kb

input:

potato

output:

1 1
1 2
3 3
3 4
3 5
5 6

result:

ok 12 tokens

Test #2:

score: 0
Accepted
time: 1ms
memory: 5584kb

input:

pbpbppb

output:

1 1
1 2
1 3
1 4
1 5
5 6
5 7

result:

ok 14 tokens

Test #3:

score: 0
Accepted
time: 3ms
memory: 5880kb

input:

dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd...

output:

1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 61
1 62...

result:

ok 1990 tokens

Test #4:

score: -100
Time Limit Exceeded

input:

gtgggtgttgggggtgtgggtgttggtttggggtggtgtgggttggtggggtgggttgttggttgggtttggggtgttgggggtgggttttggttgttggtggggttgttggtggtggggtgggttttgggttggtgggtgggtggttgtgttggttttttttgttgggtttgggtgttgttgtggtgggttttggttggggtgttggttggtgtggtgtgggttttggttttttgtttgtggtggtgttttgtttttggtggggtgtttgttgttttggggttggggtgggggttgtgg...

output:

1 1
2 2
2 3
2 4
2 5
2 6
2 7
8 8
8 9

result: