QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#455375 | #7008. Rikka with Nice Counting Striking Back | D_F_S | AC ✓ | 7555ms | 197804kb | C++14 | 1.9kb | 2024-06-26 12:35:20 | 2024-06-26 12:35:20 |
Judging History
answer
#include<bits/stdc++.h>
#define inl inline
using namespace std;
typedef long long ll;
const int N=4e5+5,IB=1<<21; char IN[IB],*IS=IN+IB,*IT=IS;
#define gc() (IS==IT&&(IT=IN+fread(IS=IN,1,IB,stdin)),IS==IT?EOF:*IS++)
int T,n,dc,la,a[N],fa[N],le[N],ch[N][26],d[N],vs[N];
ll an; queue<int> q; vector<int> e[N]; set<int> s[N],f[N];
inl int RD()
{
int s=0; char c; while(!isdigit(c=gc()));
for(;isdigit(c);s=s*10+c-48,c=gc()); return s;
}
inl void Ins(int v)
{
int p=++dc,f=la,q,t; le[la=p]=le[f]+1; for(;!ch[f][v];ch[f][v]=p,f=fa[f]);
if(!f) {fa[p]=1; return; } if(le[q=ch[f][v]]==le[f]+1) {fa[p]=q; return; }
le[t=++dc]=le[f]+1; fa[t]=fa[q]; fa[q]=fa[p]=t; memcpy(ch[t],ch[q],sizeof(ch[t]));
for(;ch[f][v]==q;ch[f][v]=t,f=fa[f]);
}
inl void MG(int x,int y)
{
s[x].size()<s[y].size()&&(swap(s[x],s[y]),swap(f[x],f[y]),0);
for(int u:s[y])
{
auto i=s[x].insert(u).first,j=i,k=i; ++k;
if(k==s[x].end()) j!=s[x].begin()&&(f[x].insert(u-*--j),0);
else j!=s[x].begin()&&(f[x].erase(*k-*--j),f[x].insert(u-*j),0), f[x].insert(*k-u);
}
}
int main()
{
for(T=RD();T--;printf("%lld\n",an),an=0)
{
char c; while(!isalpha(c=gc())); for(n=0;isalpha(c);a[++n]=c-97,c=gc());
for(int i=0;i<=n*2;vs[i++]=0) memset(ch[i],0,sizeof(ch[i])), s[i].clear(), f[i].clear(), e[i].clear();
for(int i=la=dc=1;i<=n;Ins(a[i]),s[la].insert(i++));
for(int i=2;i<=dc;++i) ++d[fa[i]], e[fa[i]].push_back(i); for(int i=1;i<=dc;++i) !d[i]&&(q.push(i),0);
for(int u,l,r,v,j;!q.empty();q.pop()) if((u=q.front())>1)
{
sort(e[u].begin(),e[u].end(),[](int x,int y){return s[x].size()>s[y].size(); });
l=le[fa[u]]+1; r=le[u]; an+=r-l+1; for(int v:e[u]) MG(u,v);
for(int t;!f[u].empty()&&(t=*f[u].rbegin())>r;f[u].erase(t));
for(auto i=f[u].begin();i!=f[u].end();) if(vs[v=*i]==u) i=f[u].erase(i);
else for(++i,j=(l-1)/v*v+v;j<=r;j+=v) vs[j]!=u&&(--an,vs[j]=u);
!--d[fa[u]]&&(q.push(fa[u]),0);
}
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 8ms
memory: 59740kb
input:
6 rikkasuggeststoallthecontestants thisisaproblemdesignedforgrandmasters ifyoudidnotachievethat youdbetterskiptheproblem wishyouahighrank enjoytheexperience
output:
500 679 244 290 132 163
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 7555ms
memory: 197804kb
input:
1000 mxsslrrxtwwnwlsrxxxbsmtxxwwntsbrwlxnbxunutnlmrrlubturuwmbnobrolwunwurtbnmlumxmwtwrsulruxslsnltsstmmxbsmuonroubrnnmu sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss glggglgg yykkyyyykykykyyyykyykykkkyyyykkyykkkyyykykyykyyykkykky...
output:
6522 1 20 9443 11294 1 8619 26 7898 260905 9048 6 22114 52 20 45 7 39 10 1 28 26 10 47 32 12977 30 13 7473 12 8402 1 8083 16 1 10462 16 9278 1 1 8968 7858 11148 8130 6 8516 12223 9266 8374 26 45 14 10150 9 10175 298758 203677 11522 12 8985 10687 12 1 6613277686 10 10 1 5794 28 1 280529 7874 13 10564...
result:
ok 1000 lines
Test #3:
score: 0
Accepted
time: 2837ms
memory: 181904kb
input:
26 hihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihh...
output:
9523687993 9529757593 9537405289 9539347561 9533035177 9528058105 564250 9522959641 9542382361 9518953705 9519439273 9534977449 9519803449 9535705801 9519560665 9534249097 9527572537 9523687993 9539468953 9532064041 9525873049 9532185433 9541168441 9524901913 9531092905 9518832313
result:
ok 26 lines
Test #4:
score: 0
Accepted
time: 3140ms
memory: 181168kb
input:
26 oohooohoohooohoohooohoohoohooohoohooohoohoohooohoohooohoohoohooohoohooohoohooohoohoohooohoohooohoohoohooohoohooohoohooohoohoohooohoohooohoohoohooohoohooohoohooohoohoohooohoohooohoohoohooohoohooohoohoohooohoohooohoohooohoohoohooohoohooohoohoohooohoohooohoohooohoohoohooohoohooohoohoohooohoohooohooh...
output:
9625902365 9628810517 9622671085 9626467839 9628891299 9626306275 9630668503 9620409189 9618228075 9622428739 9628406607 9625336891 9630426157 9626871749 9620086061 9626144711 9616935563 9617177909 9626790967 9627194877 9626467839 354971 9616370089 9618308857 9617824165 9616773999
result:
ok 26 lines
Test #5:
score: 0
Accepted
time: 3264ms
memory: 180824kb
input:
26 vggvgvggvgvvgvggvgvggvgvvggvgvggvgvvgvggvgvggvgvvgvggvgvvggvgvggvgvvgvggvgvggvgvvgvggvgvggvgvvggvgvggvgvvgvggvgvggvgvvgvggvgvvggvgvggvgvvgvggvgvggvgvvggvgvggvgvvgvggvgvggvgvvgvggvgvggvgvvggvgvggvgvvgvggvgvggvgvvgvggvgvvggvgvggvgvvgvggvgvggvgvvggvgvggvgvvgvggvgvggvgvvgvggvgvvggvgvggvgvvgvggvgvggvg...
output:
13085098340 13073668733 13071665606 13067070197 13077910649 13074964874 13078735466 13070840789 13072726085 13067895014 669720 13065891887 13065302732 13076496677 13068484169 13064242253 13065420563 13063181774 13080502931 13067070197 13072490423 13070015972 13083802199 13064831408 13075671860 13085...
result:
ok 26 lines