Nonsense Time

时间限制: 10 Sec  内存限制: 128 MB

题目描述

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。
思路:前置知识:长度为N的全排列的LIS的期望为sqrt(N),于是可以倒着让这些数变得不可用,如果它不是LIS上的数就对答案没影响,否则就暴力重新nlogn跑LIS。因为LIS的期望长度为sqrt(N),所以删除某一个数,该数是LIS上的数的概率是1/sqrt(N),也就是说期望会有sqrt(N)个数在LIS上,于是我们最多跑sqrt(N)遍暴力,期望复杂度:O(n*sqrt(n)*log(n))。
#include<bits/stdc++.h>
using namespace std;
const int N = ;
int arr[N],b[N]={},len;
int k[N],vis[N]={};
int pre[N];
int if_lis[N],id[N]; int Serach(int num,int low,int high)
{
int mid;
while (low<=high) {
mid=(low+high)>>;
if (num>=b[mid]) low=mid+;
else high=mid-;
}
return low;
} void DP(int n)
{
len=;
b[len]=-;
id[len]=-;
for(int i=;i<=n;i++)
{
if(!vis[i])continue;
if(arr[i]>=b[len])
{
len++;
b[len]=arr[i]; id[len]=i;
pre[i]=id[len-];
}
else
{
int pos=Serach(arr[i],,len);
b[pos]=arr[i]; pre[i]=id[pos-];
id[pos]=i;
}
} memset(if_lis,,sizeof(if_lis));
int now=id[len];
while(now!=-)
{
if_lis[now]=;
now=pre[now];
}
} int ans[N];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&arr[i]);
for(int i=;i<=n;i++)scanf("%d",&k[i]);
for(int i=;i<=n;i++)vis[i]=; DP(n);
ans[n]=len; for(int i=n-;i>=;i--)
{
vis[k[i+]]=;
if(!if_lis[k[i+]])
{
ans[i]=ans[i+];
continue;
}
DP(n);
ans[i]=len;
}
for(int i=;i<=n;i++)printf("%d%c",ans[i],i==n ? '\n' : ' ');
}
return ;
}

Nonsense Time的更多相关文章

  1. Nonsense Alphabet

    Nonsense Alphabet A was an ant Who seldom stood still, And who made a nice house In the side of a hi ...

  2. 【HDU6635】Nonsense Time

    题目大意:给定一个长度为 N 的序列,开始时所有的位置都不可用,每经过一个时间单位,都会有一个位置被激活.现给定激活顺序的序列,求每次激活之后全局的最长上升子序列的长度,保证数据随机. 题解: 引理: ...

  3. [2019杭电多校第六场][hdu6635]Nonsense Time

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6635 题意是说一开始所有数都冻结,第i秒会解冻第ki个数,求每秒状态下的最长上上升子序列长度. 这种题 ...

  4. 【HDOJ6635】Nonsense Time(时间倒流,lis)

    题意:给定n个数的数列,第i个数为a[i],刚开始所有位置都处于禁用状态,第i次之后位置p[i]变为可用,求每次变化后的lis长度 n,a[i],p[i]<=5e4 保证a[i],p[i]均为随 ...

  5. 2019 Multi-University Training Contest 6 Nonsense Time (纯暴力)

    题意:给你一个n的排列,起初这些数都不能用, 然后还有一个数组 第 i 个数表示下标为 i 的数能够使用. 问每一个 i 对应的最长上升子序列. 题解: 可以通过倒推,从后往前考虑转化一下 ,然后就是 ...

  6. 软件公司为何要放弃MongoDB?

    本文转至:http://database.51cto.com/art/201503/469510_all.htm(只作转载, 不代表本站和博主同意文中观点或证实文中信息) Olery成立于2010年, ...

  7. PHP开发工具+电子书+视频教程等资料下载汇总

    本汇总帖包括如下内容: PHP开发工具.PHP IDE PHP学习资源 基础.进阶类 PHP学习资源 高级及应用类 经典PHP视频教程系列 1. PHP开发工具.PHP IDE: PHP开发工具:Ze ...

  8. ACM 计算几何中的精度问题(转)

    http://www.cnblogs.com/acsmile/archive/2011/05/09/2040918.html 计算几何头疼的地方一般在于代码量大和精度问题,代码量问题只要平时注意积累模 ...

  9. C++之路进阶——poj3461(Oulipo)

    Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 35694   Accepted: 14424 Descript ...

随机推荐

  1. 统计学习笔记之k近邻法

    1.kNN算法的思想:给定一个训练数据集,对新的输入实例,在训练集中找到与该实例最近邻的k个实例,这k个实例的多数属于某类,就把输入实例分为这个类. 2.算法 (1)根据给定的距离度量,在训练集T中找 ...

  2. godaddy账号以及域名被盗找回经历以及网络信息安全的思考

    本案涉及到公司的一些机密信息,因此涉及到机密信息,我都将会用一些其他的代号进行替代.不影响读者理解本案.我会按照时间顺序讲述本案经过,是如何一步步找回godaddy账号的. 我供职的公司是一家网络科技 ...

  3. php7 mysql_pconnect() 缺失 解决方法

    php7 兼容 MySQL 相关函数 PHP7 废除了 ”mysql.dll” ,推荐使用 mysqli 或者 pdo_mysql http://PHP.net/manual/zh/mysqlinfo ...

  4. 关于安装了sqlite对于vs的组件,重启vs后,在外面可以连接sqlite数据库,但是在建立实体模型时没有sqlite数据源的问题

    出自:http://bbs.csdn.net/topics/390917337 兄弟,刚刚在stackoverflow上找到了解决方法了http://stackoverflow.com/questio ...

  5. html 引入公共的头部和底部

  6. windows IIS 部署dotnetcore

    1.安装windows IIS 程序 ,详细过程略. 2.下载dotnet core SDK runtime 链接地址:https://dotnet.microsoft.com/download/th ...

  7. Cooki and Session

    目录 Cookie Cookie的由来 什么是Cookie Cookie的原理 查看Cookie Django中操作Cookie 获取Cookie 设置Cookie 删除Cookie Session ...

  8. ES6之主要知识点(六)数组

    引自http://es6.ruanyifeng.com/#docs/array 1.扩展运算符(...) 扩展运算符(spread)是三个点(...).它好比 rest 参数的逆运算,将一个数组转为用 ...

  9. Linux 启动dubbo管控台:

  10. 网络结构解读之inception系列五:Inception V4

    网络结构解读之inception系列五:Inception V4 在残差逐渐当道时,google开始研究inception和残差网络的性能差异以及结合的可能性,并且给出了实验结构. 本文思想阐述不多, ...