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. vue+el-menu+vue-router实现动态导航条

    导航栏组件template <template> <div class="sidebar"> <el-menu unique-opened :defa ...

  2. Python flask 构建可扩展的restful apl✍✍✍

    Python flask 构建可扩展的restful apl  整个课程都看完了,这个课程的分享可以往下看,下面有链接,之前做java开发也做了一些年头,也分享下自己看这个视频的感受,单论单个知识点课 ...

  3. 记录:使用springboot的cors和vue的axios进行跨域

    一.编写一个配置类,并且注册CorsFilter: 注意允许跨域的域名不要写错 @Configuration public class ZysuyuanCorsConfiguration { @Bea ...

  4. art-template官方文档

    http://aui.github.io/art-template/zh-cn/docs/

  5. fiddler抓包工具遇到的问题-------502报错

    遇到的问题: 打开浏览器,输入本机的虚拟机地址的bugfree,出现无法连接的提示,具体是: [Fiddler] The connection to '192.168.211.128' failed. ...

  6. JS 作用域、原型链

    看到一道好题,并附答案 function Foo() { getName = function () { console.log('1'); }; return this; } Foo.getName ...

  7. Java-MyBatis-MyBatis3-XML映射文件:insert, update 和 delete

    ylbtech-Java-MyBatis-MyBatis3-XML映射文件:insert, update 和 delete 1.返回顶部 1. insert, update 和 delete 数据变更 ...

  8. SPSS科普 | 统计描述

    SPSS科普 | 统计描述 统计描述的目的就是了解数据的基本特征和分布规律,为进一步合理地选择统计方法提供依据.常用的有Frequencies.Descriptives 和Explore过程. 一.F ...

  9. C++ 连接上期所CTP交易行情接口

    CTP相关接口和文档下载: http://www.simnow.com.cn/static/softwareDownload.action 相关库文件以及头文件如下: 遇到的问题: 1.运行直接退出了 ...

  10. C++ 字符串、string、char *、char[]、const char*的转换和区别

    1.字符串 字符串本质就是一串字符,在C++中大家想到字符串往往第一反应是std::string(后面简称string) 字符串得从C语言说起,string其实是个类,C语言是没有class的,所以C ...