标签:bit turn namespace img tor long mic include for
题意:给定n个数的数列,第i个数为a[i],刚开始所有位置都处于禁用状态,第i次之后位置p[i]变为可用,求每次变化后的lis长度
n,a[i],p[i]<=5e4
保证a[i],p[i]均为随机生成的排列
思路:不知道非随机版本能不能树套树解决
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef unsigned int uint; 5 typedef unsigned long long ull; 6 typedef pair<int,int> PII; 7 typedef pair<ll,ll> Pll; 8 typedef vector<int> VI; 9 typedef vector<PII> VII; 10 //typedef pair<ll,ll>P; 11 #define N 100010 12 #define M 200010 13 #define fi first 14 #define se second 15 #define MP make_pair 16 #define pb push_back 17 #define pi acos(-1) 18 #define mem(a,b) memset(a,b,sizeof(a)) 19 #define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++) 20 #define per(i,a,b) for(int i=(int)a;i>=(int)b;i--) 21 #define lowbit(x) x&(-x) 22 #define Rand (rand()*(1<<16)+rand()) 23 #define id(x) ((x)<=B?(x):m-n/(x)+1) 24 #define ls p<<1 25 #define rs p<<1|1 26 27 const int MOD=1e9+7,inv2=(MOD+1)/2; 28 double eps=1e-4; 29 int INF=1e9; 30 int inf=0x7fffffff; 31 int dx[4]={-1,1,0,0}; 32 int dy[4]={0,0,-1,1}; 33 34 struct node 35 { 36 int x,y; 37 }q[N]; 38 39 int dp[N],a[N],b[N],c[N],d[N],pre[N],ans[N],n; 40 41 int read() 42 { 43 int v=0,f=1; 44 char c=getchar(); 45 while(c<48||57<c) {if(c==‘-‘) f=-1; c=getchar();} 46 while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar(); 47 return v*f; 48 } 49 50 int lis() 51 { 52 q[1].x=0; 53 q[1].y=0; 54 rep(i,2,n) 55 { 56 q[i].x=INF; 57 q[i].y=0; 58 } 59 rep(i,1,n) pre[i]=0; 60 int s=0; 61 rep(i,1,n) 62 if(c[i]) 63 { 64 s++; 65 int l=1,r=s,last=1; 66 while(l<=r) 67 { 68 int mid=(l+r)>>1; 69 if(q[mid].x<=a[i]){last=mid; l=mid+1;} 70 else r=mid-1; 71 } 72 dp[i]=last; pre[i]=q[last].y; 73 if(q[last+1].x>a[i]||q[last+1].y==0) 74 { 75 q[last+1].x=a[i]; 76 q[last+1].y=i; 77 } 78 } 79 int res=1,k=1; 80 rep(i,1,n) 81 if(c[i]&&dp[i]>res){res=dp[i]; k=i;} 82 rep(i,1,n) d[i]=0; 83 while(k) 84 { 85 d[k]=1; 86 k=pre[k]; 87 } 88 return res; 89 } 90 91 void solve() 92 { 93 n=read(); 94 rep(i,1,n) a[i]=read(); 95 rep(i,1,n) b[i]=read(); 96 rep(i,1,n) c[i]=1; 97 ans[n]=lis(); 98 per(i,n-1,1) 99 { 100 c[b[i+1]]=0; 101 if(d[b[i+1]]) ans[i]=lis(); 102 else ans[i]=ans[i+1]; 103 } 104 rep(i,1,n-1) printf("%d ",ans[i]); 105 printf("%d\n",ans[n]); 106 } 107 108 int main() 109 { 110 int cas=read(); 111 while(cas--) solve(); 112 return 0; 113 }
【HDOJ6635】Nonsense Time(时间倒流,lis)
标签:bit turn namespace img tor long mic include for
原文地址:https://www.cnblogs.com/myx12345/p/11650764.html