标签:啊啊啊 format rip shortcut hid color 最长上升子序列 hide form
#include<cstdio> #include<iostream> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> typedef long long ll; using namespace std; const ll N=500002; const ll oo=10000000000000000; ll op[N],f[N],head[N]; ll a[N]; int ans[N]; struct node{ ll next; ll to; }e[N]; ll cnt,n; void add(ll u,ll v){ cnt++; e[cnt].to=v; e[cnt].next=head[u]; head[u]=cnt; } void dfs(ll now){ if(op[now]==1){ ans[now]=lower_bound(f,f+1+n,oo)-(f+1); for(ll i=head[now];i;i=e[i].next) dfs(e[i].to); } if(op[now]==0){ ll ps=lower_bound(f,f+1+n,a[now])-f; ll tmp=f[ps]; f[ps]=a[now]; ans[now]=lower_bound(f,f+1+n,oo)-(f+1); for(ll i=head[now];i;i=e[i].next) dfs(e[i].to); f[ps]=tmp; } } int main(){ freopen("1059.in","r",stdin); freopen("1059.out","w",stdout); cin>>n; for(ll i=1;i<=n;i++){ cin>>op[i]>>a[i]; if(op[i]==1) add(a[i],i); else add(i-1,i); } op[0]=1; for(ll i=1;i<=n;i++) f[i]=oo; dfs(0); for(ll i=1;i<=n;i++) printf("%d\n",ans[i]); return 0; }
标签:啊啊啊 format rip shortcut hid color 最长上升子序列 hide form
原文地址:https://www.cnblogs.com/wuhu-JJJ/p/11784821.html