| Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|---|
| 41373 | LYLAKIOI | 【BJ】T3 | C++ | 解答错误 | 90 | 733 MS | 251668 KB | 2405 | 2026-04-22 15:16: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],fa[maxn]; vector<pi>v[maxn]; vector<int>v2[maxn]; int dfn[maxn],low[maxn],bel[maxn],cnt,scc,stk[maxn],top,deg[maxn]; void dfs(int u){ dfn[u]=low[u]=++cnt,stk[++top]=u; for(int x:v2[u]) if(!dfn[x])dfs(x),low[u]=min(low[u],low[x]); else if(!bel[x])low[u]=min(low[u],dfn[x]); if(dfn[u]==low[u]){ ++scc; while(top){ int p=stk[top--]; bel[p]=scc;if(p==u)break; } } } int res[maxn]; int F[maxn]; inline int fd(int u){if(F[u]==u)return u;return F[u]=fd(F[u]);} void slv(){ n=read(); up(i,1,n)rk[sa[i]=read()]=i; up(i,1,n-1)hei[i]=read(); vector<tuple<int,int,int> >E; auto link=[&](int x,int y){E.eb(x,y,0),v2[x].eb(y);}; priority_queue<pi>qhei; up(i,1,n+1)F[i]=i; up(i,1,n-1)if(hei[i]>=1)qhei.push({hei[i],i}); up(i,1,n-1)if(~hei[i])F[i]=i+1; while(!qhei.empty()){ int u=qhei.top().p2;qhei.pop(); if(sa[u]==n||sa[u+1]==n)continue; int l=rk[sa[u]+1],r=rk[sa[u+1]+1];if(l>r)swap(l,r); for(int x=fd(l);x<r;x=fd(x))hei[x]=hei[u],qhei.push({hei[x],x}),F[x]=fd(x+1); } up(i,1,n-1){ if((!hei[i])||rk[sa[i]+1]>rk[sa[i+1]+1]){E.eb(sa[i],sa[i+1],1);continue;} if(hei[i]>0)link(sa[i],sa[i+1]),link(sa[i+1],sa[i]); else link(sa[i],sa[i+1]); } up(i,1,n)if(!dfn[i])dfs(i); for(auto [x,y,w]:E)if(bel[x]!=bel[y])v[bel[x]].eb(bel[y],w),++deg[bel[y]]; queue<int>q;up(i,1,scc)if(!deg[i])q.push(i); while(!q.empty()){ int u=q.front();q.pop(); for(auto [x,w]:v[u]){ res[x]=max(res[x],res[u]+w); if(!(--deg[x]))q.push(x); } } up(i,1,n)putchar(res[bel[i]]+'a'); } int main(){ // freopen("hush.in","r",stdin),freopen("hush.out","w",stdout); slv(); return 0; }