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. Python - Virtualenv 创建虚拟环境

    Virtualenv 回到顶部 为了解决各个项目的共同依赖同一个环境,造成版本冲突等,virtualenv创建一个干净的环境,在这个环境下,进行Python项目的开发等,就成为一个个独立的项目,从而避 ...

  2. WPF 字体描边的实现方式

    原文:WPF 字体描边的实现方式   <local:TextPath x:Name="PathEdge" Fill="Red" Stroke=" ...

  3. java_缓冲流(文件内容排序)

    /** 案例:诸葛亮出师表文本排序 * 1.使用HashMap集合,k存储每行文本序,v存储文本 * 2.创建字符缓冲输入流,构造方法中绑定字符输入流 * 3.使用字符串缓冲输入流中的方法readLi ...

  4. Matlab神经网络验证码识别

    本文,将会简述如何利用Matlab的强大功能,调用神经网络处理验证码的识别问题.  预备知识,Matlab基础编程,神经网络基础.  可以先看下: Matlab基础视频教程 Matlab经典教程--从 ...

  5. ZOJ2562

    ZOJ2562https://vjudge.net/problem/11781/origin<=n的且因子数最多的那个数做法:同因子数取最小,dfs更新答案 #include <iostr ...

  6. SPOJ - The last digit

    https://vjudge.net/problem/SPOJ-LASTDIG 求最后一位,%10就完了 这个题居然要求代码小于等于700B #include <iostream> #in ...

  7. [JZOJ3171] 【GDOI2013模拟4】重心

    题目 描述 题目大意 有一堆长为222的矩形,最下面的右端点横坐标为000. 每个矩形都有其固定的质量. 将这些矩形堆在一起,使得最右边的横坐标最大,并且满足它不会塌掉(满足物理学). 思考历程 首先 ...

  8. LUOGU P4281 [AHOI2008]紧急集合 / 聚会 (lca)

    传送门 解题思路 可以通过手玩或打表发现,其实要选的点一定是他们三个两两配对后其中一对的$lca$上,那么就直接算出来所有的$lca$,比较大小就行了. #include<iostream> ...

  9. 服务器迁移部署OmsWeb

    绑定 基本设置 高级设置

  10. PHP实现图片的汉明码提取与降维

    作者感言:数学不好,遇到算法问题分分钟狗带,毫无转寰的余地-_-||| 最近心血来潮,看了相似图片的搜索,最最最初级的方法即提取汉明码,之后匹配汉明距离.当然,在数以亿计的汉明码中,要筛出需要的图片, ...