QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#334911#7406. Longest Lyndon PrefixKevin5307AC ✓270ms7108kbC++201.9kb2024-02-22 15:06:582024-02-22 15:06:58

Judging History

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

  • [2024-02-22 15:06:58]
  • 评测
  • 测评结果:AC
  • 用时:270ms
  • 内存:7108kb
  • [2024-02-22 15:06:58]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
mt19937_64 rnd(time(0));
const ll mod=998244353,base=rnd()%1000+400;
ll H[100100];
ll pw[100100];
ll get(int l,int r)
{
	return (H[r]-H[l-1]*pw[r-l+1]%mod+mod)%mod;
}
int n;
int bit[100100];
void update(int p,int v)
{
	while(p<=n)
	{
		bit[p]=min(bit[p],v);
		p+=(p&(-p));
	}
}
int query(int p)
{
	int ans=inf;
	while(p)
	{
		ans=min(ans,bit[p]);
		p-=(p&(-p));
	}
	return ans;
}
int ind[100100];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	pw[0]=1;
	for(int i=1;i<100100;i++)
		pw[i]=pw[i-1]*base%mod;
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n;
		string s;
		cin>>s;
		for(int i=1;i<=n;i++)
			bit[i]=n+1;
		for(int i=0;i<n;i++)
			H[i+1]=(H[i]*base+s[i])%mod;
		vector<int> vec;
		for(int i=1;i<=n;i++)
			vec.pb(i);
		sort(ALL(vec),[&](int a,int b)
		{
			int len=n-max(a,b)+1;
			int l=0,r=len;
			while(l<r)
			{
				int mid=(l+r+1)/2;
				if(get(a,a+mid-1)==get(b,b+mid-1))
					l=mid;
				else
					r=mid-1;
			}
			if(l==len)
				return a>b;
			return s[a+l-1]<s[b+l-1];
		});
		for(int i=1;i<=n;i++)
			ind[vec[i-1]]=i;
		vector<int> ans;
		for(int i=n;i>=1;i--)
		{
			ans.pb(query(ind[i])-i);
			update(ind[i],i);
		}
		rev(ans);
		for(auto x:ans)
			cout<<x<<" ";
		cout<<'\n';
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

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

input:

3
3
aaa
3
aab
3
cba

output:

1 1 1 
3 2 1 
1 1 1 

result:

ok 9 numbers

Test #2:

score: 0
Accepted
time: 9ms
memory: 5776kb

input:

10000
10
ababbbbaaa
6
aabbaa
3
abb
9
bababbbbb
9
abbaaaaaa
8
ababbaab
7
abbbbbb
7
aaabaaa
2
ba
10
abaababbab
2
ab
1
a
1
a
5
ababa
6
aaabba
2
ba
4
abba
5
bbbba
9
aabbbbbaa
10
baaabaaaba
10
babbbbbbaa
9
babaaabba
1
b
6
abbbaa
7
aaaaaab
10
baaaaabaaa
9
bbbbabbba
3
bbb
8
abaababa
7
bbbbaba
5
ababb
1
b
7...

output:

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

result:

ok 54963 numbers

Test #3:

score: 0
Accepted
time: 9ms
memory: 4524kb

input:

10000
4
cbcc
7
cccbcac
3
cac
3
cba
6
caaacb
9
aaabaccac
8
acbabbab
7
cbabcac
2
ba
4
caab
4
bcac
8
aacabcac
8
cbbbacab
7
cbcacca
4
aaac
3
bac
10
acacbabaab
6
ccabba
6
cbccca
5
cbabb
9
acacbcbba
1
c
9
aaacacaba
10
aacbaaacbc
5
bbaac
8
bbaabbab
3
bac
3
cbb
3
caa
3
abb
2
bc
8
abcacbca
6
bbabab
5
bcbca
1...

output:

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

result:

ok 54644 numbers

Test #4:

score: 0
Accepted
time: 9ms
memory: 4520kb

input:

10000
8
fddfiagb
5
cabjf
9
cgcbjbdfd
1
a
1
j
3
gcg
3
gba
7
cagdcfh
6
jaidja
2
fh
5
iefej
1
c
7
ggdghae
8
aeaibgge
6
bgihie
9
dhafgiief
6
bhcjih
7
iaajfhe
1
g
1
h
2
hb
3
bac
6
gfdcgc
4
fiad
9
gchaceeaj
10
agjacfdggg
9
bbhiffbgg
8
eeeefjcf
7
afcgiea
2
gj
8
gbiijidi
1
b
6
jejdea
3
fcc
6
ghaijb
10
cecgd...

output:

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

result:

ok 54830 numbers

Test #5:

score: 0
Accepted
time: 9ms
memory: 4760kb

input:

10000
6
wjgjli
2
um
10
ztmekuwlby
10
waawouorxc
7
juqxdzu
5
kimcu
6
euxxiw
5
uizus
7
wpuyrwg
8
tsdbixbu
8
qsparfin
3
jwn
5
pbiul
9
dcglefecs
1
u
7
sprjnyj
10
npiglkutgk
3
ihv
10
hkjelyarxa
9
abswbhkuw
9
ngohupqot
2
am
3
aax
7
lfpljzo
6
kgetfz
5
wbvwv
6
indqlw
3
qym
4
sddd
2
mt
7
klzloba
9
myifxnhkw
...

output:

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

result:

ok 55358 numbers

Test #6:

score: 0
Accepted
time: 18ms
memory: 4760kb

input:

1000
23
jdefdahaejiebhbbachgbea
10
eccjdgfdfd
45
aggeechjbaabeccaghcehahgeadahaececgghgijiajdh
32
bgfafgbhechfjbcjadcdbabhgbdgcehf
49
jcabigjdhfaagahjihebibffdebhdgjeiiijjacahiaggcibg
17
gifciaaaechbehbie
82
bcdegeehagadfhfagajfibiegifcfjddibhjhifceijjgedadgighaffcjehaihahcddbjjhghghieafec
88
jiieba...

output:

1 3 2 1 1 2 1 9 3 1 1 1 2 1 1 1 6 3 1 1 2 1 1 
1 9 8 1 3 1 1 2 1 1 
9 1 1 1 1 3 2 1 1 36 35 4 1 1 1 10 2 1 3 2 1 4 1 1 1 20 1 2 1 16 1 10 1 8 7 6 1 4 2 1 1 4 1 2 1 
3 1 1 13 2 1 7 1 1 4 1 2 1 3 2 1 5 1 2 1 1 11 3 1 1 7 2 1 4 3 1 1 
1 1 8 7 1 2 1 3 1 1 39 26 1 24 3 1 1 1 1 2 1 16 1 1 2 1 11 1 9 2 1 6...

result:

ok 52575 numbers

Test #7:

score: 0
Accepted
time: 37ms
memory: 4544kb

input:

100
958
bcaegajcfehihhaijijiagcdhchdgacaiffhcgeacceefbfedebddghdefjjchabccdfdhfafihcjcjhdjbhhaeececaiebiejahgdceicfbdcaegjjaecbfhiegabhcbbjgibhdaeegaffefjfjbhiaiccaccicigfjdjabfdagbdbbbahddfjbgfcgdccgehcijfhjeahefbcjfedacdghjbcedigcijihbajfcfeejgedebcjcgjfbaiabcbcciejehbhjegfagajdaedhijjfiaigifgheff...

output:

2 1 27 2 1 9 1 7 1 5 2 1 1 1 6 2 1 2 1 1 9 1 7 2 1 4 1 2 1 33 1 8 1 3 2 1 3 1 1 23 5 4 3 2 1 5 1 1 2 1 12 9 3 2 1 5 4 3 1 1 2 1 189 8 7 6 5 1 3 1 1 14 3 1 1 7 1 5 1 1 2 1 3 1 1 30 1 1 2 1 1 7 1 1 4 1 2 1 12 1 1 1 5 2 1 2 1 3 1 1 5 4 3 1 1 9 1 1 6 3 2 1 2 1 42 3 1 1 8 4 1 2 1 3 1 1 19 3 2 1 15 1 1 5 ...

result:

ok 52113 numbers

Test #8:

score: 0
Accepted
time: 32ms
memory: 4648kb

input:

100
917
urldtufacwbinfdubedmcwhgopzwzdgctwdxzdpkjdvsjqwhfmxlbjaniolzgfjetehrqvcvxmbpkcgccxteriwvzuhflkbhqkzzqcuodovddiitnmjnptqpnrvoqdhvpcvbzqejvkecwaynsuqkvbubwouwrmzqqlkelnculupjheobidrworymefjhvggxeofaksrokysyrnndbfcwsntyvcojnoyumlalojfjvtfejqcbvjlizdyneegubsfucawlurjletoyjfxegalalcnytyjjjiwzkbkc...

output:

1 1 1 4 2 1 1 746 2 1 6 2 1 1 2 1 38 1 2 1 11 1 1 6 5 4 1 2 1 2 1 21 2 1 3 2 1 15 1 1 1 11 1 1 3 2 1 1 4 2 1 1 2 1 141 1 4 1 2 1 1 2 1 2 1 5 4 1 2 1 4 2 1 1 20 1 1 2 1 15 14 1 1 11 1 5 1 2 1 1 1 3 1 1 47 6 1 4 1 1 1 30 1 1 3 2 1 22 17 16 15 1 1 1 11 10 3 1 1 1 5 2 1 2 1 4 3 1 1 2 1 10 1 1 4 3 1 1 1 ...

result:

ok 48866 numbers

Test #9:

score: 0
Accepted
time: 226ms
memory: 7076kb

input:

1
100000
bbbabaabaaabaabbbabaababbabbbabaaaababbabaababbaababbabbbbaaababbaaaaabaabbbabbbaababaabbaabbababbabbabababbaaaabbabbbbbbbbbbabaabbbabbbaaaabaaaaaabbbaababaaabbaabaabbaabbaaabababbaabbaaaaaabbbaaabaababbbbbaaaabbaababaabbbbbbabababaabababaaaabbbbbbaabbbabaaaabbbababaaaabbaaaaaabbabaaabaabba...

output:

1 1 1 2 1 3 2 1 23 22 2 1 7 4 1 1 1 2 1 12 9 1 7 1 1 4 1 1 1 2 1 34 26 8 5 1 3 1 1 2 1 17 5 1 3 1 1 11 10 1 8 1 1 5 1 1 1 1 7 6 5 1 3 1 1 76 70 41 40 2 1 9 4 1 1 1 4 1 1 1 28 2 1 2 1 23 3 1 1 19 3 1 1 8 1 3 1 1 3 1 1 7 1 5 1 3 1 1 28 27 26 14 1 1 11 1 1 1 1 1 1 1 1 1 1 2 1 9 4 1 1 1 4 1 1 1 5 4 3 2 ...

result:

ok 100000 numbers

Test #10:

score: 0
Accepted
time: 206ms
memory: 6960kb

input:

1
100000
caabbccaaabcbbbcacbbbbbaabacabcaacacbabbcacacaaccacbbccbabbaccccbaccabcabacbbccccacbabaccacbaaabcccacaccbbaaacbbbcacbccbaaaabaabbaacaaacaaacbaacbcaaacccabcccbbacccccaacbccabbbcaccaaaccbcccbbcbacccaaacbaabaaabaabaccccccbcccccaabcaacbbcbbaacbccabccbbbbabbcbcbcbabcbaaabccccaaabacaaacaaabbabbca...

output:

1 6 5 4 3 1 1 113 15 14 2 1 4 3 2 1 7 1 1 1 1 1 1 69 7 1 2 1 3 2 1 61 5 1 3 1 1 8 3 2 1 2 1 2 1 47 3 1 1 7 1 4 3 1 1 1 15 1 1 6 1 1 1 1 1 3 1 1 3 2 1 21 1 8 1 6 5 1 1 1 1 3 1 1 8 1 3 1 1 3 1 1 28 13 12 4 1 1 1 7 1 5 1 1 1 1 14 13 12 1 4 3 2 1 6 1 3 1 1 1 180 83 10 2 1 7 3 1 1 3 2 1 72 3 2 1 60 9 3 1...

result:

ok 100000 numbers

Test #11:

score: 0
Accepted
time: 206ms
memory: 6992kb

input:

1
100000
hbjlrpypvmluheuxuoquywmrtabyafdpxbvahkvzbqachlachljnappbkfetpkkvazifiswufsuxedthevgdtpljopiqgrtkajrblfflhnmtapnqiwzhphkmimlooxnyltzbskmgybtfgovrduecgarajrvotkaewgedvzaldsxksqyhfajrjdjapnfwgtrwgiraaqafcooyiryhmvtgfspqayywtleaduegvigxpuqmojqbvbdpwficpditskecryzbciajujgrwxglfwpjinrjuwfwsqqwjus...

output:

1 24 10 9 1 2 1 2 1 1 2 1 1 12 2 1 1 5 4 3 1 1 3 2 1 170 2 1 14 1 3 2 1 2 1 7 4 3 2 1 2 1 153 3 2 1 149 5 4 1 2 1 44 1 1 9 1 1 6 1 1 3 2 1 32 1 1 9 4 3 1 1 4 3 2 1 1 19 1 1 3 1 1 13 1 1 1 3 2 1 2 1 4 2 1 1 62 2 1 9 1 7 6 1 4 1 2 1 43 1 2 1 3 2 1 2 1 14 2 1 11 1 9 3 2 1 2 1 3 2 1 18 1 2 1 2 1 12 1 5 ...

result:

ok 100000 numbers

Test #12:

score: 0
Accepted
time: 270ms
memory: 6992kb

input:

1
100000
abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabahabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabaiabacabadabacabaeabacabadabacabafaba...

output:

65536 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 32 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 64 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 32 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 128 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1...

result:

ok 100000 numbers

Test #13:

score: 0
Accepted
time: 142ms
memory: 7108kb

input:

1
100000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok 100000 numbers

Test #14:

score: 0
Accepted
time: 197ms
memory: 6948kb

input:

1
100000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951...

result:

ok 100000 numbers

Test #15:

score: 0
Accepted
time: 142ms
memory: 6904kb

input:

1
100000
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok 100000 numbers

Extra Test:

score: 0
Extra Test Passed