Nonsense Time

题目描述

You a given a permutation p1,p2,…,pn of size n. Initially, all elements in p are frozen. There will be n stages that these elements will become available one by one. On stage i, the element pki will become available.

For each i, find the longest increasing subsequence among available elements after the first i stages.

 

输入

The first line of the input contains an integer T(1≤T≤3), denoting the number of test cases.
In each test case, there is one integer n(1≤n≤50000) in the first line, denoting the size of permutation.
In the second line, there are n distinct integers p1,p2,...,pn(1≤pi≤n), denoting the permutation.
In the third line, there are n distinct integers k1,k2,...,kn(1≤ki≤n), describing each stage.
It is guaranteed that p1,p2,...,pn and k1,k2,...,kn are generated randomly.

 

输出

For each test case, print a single line containing n integers, where the i-th integer denotes the length of the longest increasing subsequence among available elements after the first i stages.

 

样例输入

复制样例数据

1
5
2 5 3 1 4
1 4 5 3 2

样例输出

1 1 2 3 3

 

杭电第六场,正难则反,根据题解补的题,主要学会求lis的nlogn算法,运用二分

#pragma GCC optimize(2)
#include
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod=1e9+7;
const int modp=998244353;
const int maxn=5e4+50;
const double eps=1e-6;
#define lowbit(x)  x&(-x)
#define INF 0x3f3f3f3f
const double inf=0x7fffffff;
inline ll read()
{
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int dcmp(double x)
{
    if(fabs(x)0)?1:-1;
}
int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}
ll qmod(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a)%mod;
        }
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}
int n;
int a[maxn],dp[maxn],pos[maxn],vis[maxn],ans[maxn],len[maxn];
void lis(){
    for(register int i=0;i<=n;++i){
        dp[i]=INF;
        len[i]=-1;
        vis[i]=0;
    }
    int maxx=0;
 
    for(register int i=0;i=0;--i){
        if(maxx<0){
            break;
        }
        if(len[i]==maxx){
            vis[i]=1;
            maxx--;
        }
    }
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
        n=read();
        for(register int i=0;i=0;--i){
            ans[i]=lower_bound(dp,dp+n,INF)-dp;
            if(vis[pos[i]]==1){
                a[pos[i]]=-1;
                lis();
            }
            else{
                a[pos[i]]=-1;
            }
        }
 
        for(register int i=0;i

 

你可能感兴趣的:(基本算法,动态规划)