标签:warning clu second char code har auto c++ space
#include<bits/stdc++.h> #define reg register int #define il inline #define fi first #define se second #define mk(a,b) make_pair(a,b) #define numb (ch^‘0‘) #define pb push_back #define solid const auto & #define enter cout<<endl #define pii pair<int,int> using namespace std; typedef long long ll; template<class T>il void rd(T &x){ char ch;x=0;bool fl=false; while(!isdigit(ch=getchar()))(ch==‘-‘)&&(fl=true); for(x=numb;isdigit(ch=getchar());x=x*10+numb); (fl==true)&&(x=-x); } template<class T>il void output(T x){if(x/10)output(x/10);putchar(x%10+‘0‘);} template<class T>il void ot(T x){if(x<0) putchar(‘-‘),x=-x;output(x);putchar(‘ ‘);} template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar(‘\n‘);} namespace Miracle{ const int N=100000+5; const int mod=998244353; const int lim=10000; #define mid ((l+r)>>1) int n; int ans[N]; int to[N]; struct edge{ int nxt,to; int x,c; }e[N]; int hd[N],cnt; void add(int u,int v,int ct,int c){ e[++cnt].nxt=hd[u]; e[cnt].to=v; e[cnt].c=c; e[cnt].x=ct; hd[u]=cnt; } struct node{ int ls,rs; int nxt,val; int tag; node(){ ls=0;rs=0;nxt=0;val=0;tag=-1; } }t[N*80]; int tot; int rt[N][26]; int sx,sc,fc; int mx[N][26]; int fail[N]; int ad(int x,int y){ return x+y>=mod?x+y-mod:x+y; } void pushup(int x){ t[x].val=ad(t[t[x].ls].val,t[t[x].rs].val); } int cpy(int cur){ ++tot;t[tot]=t[cur];return tot; } void tag(int &x,int l,int r,int c){ cout<<" tag "<<c<<endl; x=cpy(x); t[x].tag=c; t[x].val=(ll)c*(r-l+1)%mod; } void pushdown(int x,int l,int r){ if((!x)||(t[x].tag==-1)) return; tag(t[x].ls,l,mid,t[x].tag); tag(t[x].rs,mid+1,r,t[x].tag); t[x].tag=-1; } void chan(int &x,int y,int l,int r,int L,int R,int c){ cout<<" chan "<<l<<" "<<r<<" L "<<L<<" R "<<R<<" c "<<c<<endl; if(!x){ x=cpy(y); } if(L<=l&&r<=R){ t[x].tag=c; t[x].val=(ll)c*(r-l+1)%mod; return; } pushdown(x,l,r); if(L<=mid){ t[x].ls=cpy(t[x].ls);chan(t[x].ls,t[y].ls,l,mid,L,R,c); } if(mid<R){ t[x].rs=cpy(t[x].rs);chan(t[x].rs,t[y].rs,mid+1,r,L,R,c); } pushup(x); } void upda(int &x,int y,int l,int r,int p,int to){ if(!x){ x=cpy(y); } if(l==r){ t[x].nxt=to;return; } // pushdown(x,l,r);//dele ? //warning!! no pushdown if(p<=mid){ t[x].ls=cpy(t[x].ls);upda(t[x].ls,t[y].ls,l,mid,p,to); }else{ t[x].rs=cpy(t[x].rs);upda(t[x].rs,t[y].rs,mid+1,r,p,to); } pushup(x); } int query(int x,int l,int r,int L,int R){ if(L<=l&&r<=R){ return t[x].val; } pushdown(x,l,r); if(R<=mid) return query(t[x].ls,l,mid,L,R); if(mid<L) return query(t[x].rs,mid+1,r,L,R); return ad(query(t[x].ls,l,mid,L,R),query(t[x].rs,mid+1,r,L,R)); } int fin(int x,int l,int r,int p){ if(l==r) return t[x].nxt; // pushdown(x,l,r);//dele? if(p<=mid) return fin(t[x].ls,l,mid,p); else return fin(t[x].rs,mid+1,r,p); } void dfs(int u,int len){ cout<<" dfs "<<u<<" len "<<len<<endl; cout<<" fail "<<fail[u]<<endl; //5 for(reg j=0;j<26;++j) mx[u][j]=mx[fail[u]][j]; //6 for(reg i=0;i<26;++i){ rt[u][i]=rt[fail[u]][i]; } for(reg o=hd[u];o;o=e[o].nxt){ int v=e[o].to; if(u==0) sx=e[o].x,sc=e[o].c,fc=v; int x=e[o].x,c=e[o].c; cout<<" xx "<<x<<" cc "<<c<<endl; ans[v]=ans[u]; //1 int t=min(x,mx[u][c]); cout<<" tt "<<t<<endl; int lp=query(rt[u][c],1,lim,1,x); cout<<" lp "<<lp<<endl; lp=ad((ll)t*(t+1)/2%mod,lp); ans[v]=ad(ans[v],lp); if(t<x&&sc==c){//has nxt=0 int re=x-t; if(u==0){ ans[v]=ad(ans[v],(ll)x*(x-1)/2%mod); }else{ ans[v]=ad(ans[v],(ll)re*sx%mod); } } //3 int fa=fin(rt[fail[u]][c],1,lim,x); if(fa!=0){ fail[v]=fa; }else{ if(u&&sc==c&&x>=sx){ fail[v]=fc; }else{ fail[v]=0; } } //2.1 int tmp=rt[u][c]; rt[u][c]=0; chan(rt[u][c],tmp,1,lim,1,x,len); //2.2 tmp=rt[u][c]; rt[u][c]=0; upda(rt[u][c],tmp,1,lim,x,v); //4 int od=mx[u][c]; mx[u][c]=max(mx[u][c],x); dfs(v,len+x); //warning 1 rt[u][c]=rt[fail[u]][c]; mx[u][c]=od; } } int main(){ rd(n); int now=0; int op,x;char c[233]; for(reg i=1;i<=n;++i){ rd(op); if(op==1){ rd(x);scanf("%s",c+1); cout<<c+1<<endl; add(now,i,x,c[1]-‘a‘); now=i; }else{ rd(x); to[i]=x; now=x; } } dfs(0,0); for(reg i=1;i<=n;++i){ if(to[i]) ans[i]=ans[to[i]]; } prt(ans,1,n); return 0; } } signed main(){ Miracle::main(); return 0; } /* Author: *Miracle* */
标签:warning clu second char code har auto c++ space
原文地址:https://www.cnblogs.com/Miracevin/p/10859444.html