Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
41378 LYLAKIOI 【BJ】T3 C++ 通过 100 545 MS 68084 KB 1386 2026-04-22 16:39:04

Tests(40/40):


#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define m_p make_pair #define pb push_back #define eb emplace_back using namespace std; typedef long long ll; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } const int maxn=1e6+10; int n,rk[maxn],sa[maxn],hei[maxn],cnt[maxn],res[maxn]; vector<int>E[maxn]; void slv(){ n=read(); up(i,1,n)rk[sa[i]=read()]=i; up(i,2,n)hei[i]=read();int k=0; up(i,1,n){ if(rk[i]==1){k=0;continue;} k=max(k-1,0);int x=sa[rk[i]-1]; while(k<hei[rk[i]])++cnt[min(rk[i+k],rk[x+k])],--cnt[max(rk[i+k],rk[x+k])],k++; if(~hei[rk[i]])E[x+hei[rk[i]]].eb(i+hei[rk[i]]); } up(i,1,n)cnt[i]+=cnt[i-1]; up(i,2,n)if(rk[sa[i-1]+1]>rk[sa[i]+1])E[sa[i-1]].eb(sa[i]); int mx=0; up(i,1,n){ int p=i;while(cnt[p])p++; up(k,i,p)mx=max(mx,res[sa[k]]); up(k,i,p){res[sa[k]]=mx;for(int z:E[sa[k]])res[z]=max(res[z],res[sa[k]]+1);}i=p; } up(i,1,n)putchar(res[i]+'a'); } int main(){ // freopen("hush.in","r",stdin),freopen("hush.out","w",stdout); slv(); return 0; }


测评信息: