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. 17.splash_case02

    # 抓取<我不是药神>的豆瓣评论 import csv import time import requests from lxml import etree fw = open('doub ...

  2. 14.data.js

    dict_data = { "_id":1, name:"王五", age:55, gender:true } db.stu.insert(dict_data) ...

  3. java-day04

    IntelliJ快捷键 导入包 alt + enter 删除光标所在行 ctrl + y 复制光标所在行 ctrl + d 格式代码 ctrl + alt + l 单行注释 ctrl + / 多行注释 ...

  4. 最全Linux常用命令大全

    查看系统系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMB ...

  5. sparkStreaming入门

    1.环境 jdk : 1.8 scala : 2.11.7 hadoop:2.7 spark : 2.2.0 2. 开发工具 idea 2017.2 3.maven的pom文件 <depende ...

  6. TortoiseGit可能遇到Permission denied (publickey).

    1.检测是不是没设置公钥和私钥 2.公钥有没有添加到git账户里面去 3.检测如下图路径正确不正确

  7. POJ1160 Post Office-四边形不等式优化DP

    方程 $\Large f(i,j)=min(f(i-1,k)+w(k+1,j))$ 其中$w(i,j)$表示在$[i,j]$的村庄都去一个邮局的最小距离和 证明w满足四边形不等式 设$w_k(i,j) ...

  8. windows 内核下获取进程路径

    windows 内核下获取进程路径 思路:1):在EPROCESS结构中获取.此时要用到一个导出函数:PsGetProcessImageFileName,申明如下: NTSYSAPI UCHAR *  ...

  9. 使用java代码动态配置与xml文件结合的方式使用mybatis-generator生成代码配置

    1.使用java代码动态配置与xml文件结合的方式使用mybatis-generator生成代码配置 2.上代码:在resources目录下新建:generatorConfiguration.xml文 ...

  10. 模拟+贪心——cf1131E

    超级恶心的题,写了好久,直接倒序模拟做,但是网上有博客好像是直接正序dp做的.. 因为左端点和右端点是永远不会变的,然后情况要考虑全 /* 从后往前插 只要记录左连续,右连续,中间连续 左端点一定是L ...