QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#880 | #582757 | #6624. String Problem | Soestx | Soestx | Failed. | 2024-09-22 17:29:05 | 2024-09-22 17:29:05 |
Details
Extra Test:
Accepted
time: 105ms
memory: 6068kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
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 131940 tokens
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#582757 | #6624. String Problem | Soestx | AC ✓ | 535ms | 12940kb | C++14 | 1.5kb | 2024-09-22 17:23:25 | 2024-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
*/