Nonsense Time

2023-12-31 22:40
文章标签 time nonsense

本文主要是介绍Nonsense Time,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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 = 50050;
int arr[N],b[N]={0},len;
int k[N],vis[N]={0};
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)>>1;if (num>=b[mid]) low=mid+1;else high=mid-1;}return low;
}void DP(int n)
{len=0;b[len]=-1;id[len]=-1;for(int i=1;i<=n;i++){if(!vis[i])continue;if(arr[i]>=b[len]){len++;b[len]=arr[i];id[len]=i;pre[i]=id[len-1];}else{int pos=Serach(arr[i],1,len);b[pos]=arr[i];pre[i]=id[pos-1];id[pos]=i;}}memset(if_lis,0,sizeof(if_lis));int now=id[len];while(now!=-1){if_lis[now]=1;now=pre[now];}
}int ans[N];
int main()
{int t;scanf("%d",&t);while(t--){int n;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&arr[i]);for(int i=1;i<=n;i++)scanf("%d",&k[i]);for(int i=1;i<=n;i++)vis[i]=1;DP(n);ans[n]=len;for(int i=n-1;i>=1;i--){vis[k[i+1]]=0;if(!if_lis[k[i+1]]){ans[i]=ans[i+1];continue;}DP(n);ans[i]=len;}for(int i=1;i<=n;i++)printf("%d%c",ans[i],i==n ? '\n' : ' ');}return 0;
}
View Code

 

转载于:https://www.cnblogs.com/tian-luo/p/11318478.html

这篇关于Nonsense Time的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/557336

相关文章

linux 下Time_wait过多问题解决

转自:http://blog.csdn.net/jaylong35/article/details/6605077 问题起因: 自己开发了一个服务器和客户端,通过短连接的方式来进行通讯,由于过于频繁的创建连接,导致系统连接数量被占用,不能及时释放。看了一下18888,当时吓到了。 现象: 1、外部机器不能正常连接SSH 2、内向外不能够正常的ping通过,域名也不能正常解析。

python内置模块datetime.time类详细介绍

​​​​​​​Python的datetime模块是一个强大的日期和时间处理库,它提供了多个类来处理日期和时间。主要包括几个功能类datetime.date、datetime.time、datetime.datetime、datetime.timedelta,datetime.timezone等。 ----------动动小手,非常感谢各位的点赞收藏和关注。----------- 使用datet

lua data time

local getTime = os.date(“%c”); 其中的%c可以是以下的一种:(注意大小写) %a abbreviated weekday name (e.g., Wed) %A full weekday name (e.g., Wednesday) %b abbreviated month name (e.g., Sep) %B full month name (e.g., Sep

Event Time源码分析

《2021年最新版大数据面试题全面开启更新》 flink 中Processing Time也就是处理时间在watermark定时生成、ProcessFunction中定时器与时间类型的窗口中都有使用,但是其内部是如何实现注册定时器、如何调用、如何容错保证在任务挂掉在下次重启仍然能够触发任务执行,都是我们今天的主题。首先需要了解一下在flink内部时间系统是由哪些类来共同完成这件事,下面画

大数据-121 - Flink Time Watermark 详解 附带示例详解

点一下关注吧!!!非常感谢!!持续更新!!! 目前已经更新到了: Hadoop(已更完)HDFS(已更完)MapReduce(已更完)Hive(已更完)Flume(已更完)Sqoop(已更完)Zookeeper(已更完)HBase(已更完)Redis (已更完)Kafka(已更完)Spark(已更完)Flink(正在更新!) 章节内容 上节我们完成了如下的内容: 滑动窗口:时间驱动、事件

DS简记1-Real-time Joint Object Detection and Semantic Segmentation Network for Automated Driving

创新点 1.更小的网络,更多的类别,更复杂的实验 2. 一体化 总结 终于看到一篇检测跟踪一体化的文章 网络结构如下: ResNet10是共享的Encoder,yolov2 是检测的Deconder,FCN8 是分割的Deconder。 其实很简单,论文作者也指出:Our work is closest to the recent MultiNet. We differ by focus

Go-Time

日期&时间格式化。 package mainimport ("fmt""time")func main() {now := time.Now()now_string := fmt.Sprintf("%d%02d%02d-%02d%02d%02d-Others",now.Year(), now.Month(), now.Day(),now.Hour(), now.Minute(), now.Se

音视频入门基础:WAV专题(8)——FFmpeg源码中计算WAV音频文件AVStream的time_base的实现

一、引言 本文讲解FFmpeg源码对WAV音频文件进行解复用(解封装)时,其AVStream的time_base是怎样被计算出来的。 二、FFmpeg源码中计算WAV音频文件AVStream的time_base的实现 从《音视频入门基础:WAV专题(5)——FFmpeg源码中解码WAV Header的实现》中可以知道,FFmpeg对WAV音频文件进行解复用(解封装)时,其源码内部

el-time-select 动态增加时间

<template><div><div v-for="(item, index) in timeSlots" :key="index"><el-time-select placeholder="起始时间" v-model="item.startTime" :picker-options="{start: '00:00',step: '00:15',end: '23:59',}"></el-ti

【ros2】 const builtin_interfaces::msg::Time timestamp解析

解析 const builtin_interfaces::msg::Time & timestamp 1. 数据类型 builtin_interfaces::msg::Time 是 ROS 2 中的一个消息类型,用于表示时间戳。 2. 结构 builtin_interfaces::msg::Time 包含以下字段: struct Time{std::uint32_t sec;std::