首页 > 其他分享 >Link with Monotonic Subsequence(分块,思维)

Link with Monotonic Subsequence(分块,思维)

时间:2024-03-24 21:59:17浏览次数:33  
标签:nnn permutation Monotonic lds Subsequence Link lis test rm

First, let's review some definitions. Feel free to skip this part if you are familiar with them.

A sequence aaa is an increasing (decreasing) subsequence of a sequence bbb if aaa can be obtained from bbb by deletion of several (possibly, zero or all) elements and all elements are in increasing (decreasing) order from the beginning to the end.

A permutation is an array consisting of nnn distinct integers from 111 to nnn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2][1,2,2] is not a permutation (222 appears twice in the array) and [1,3,4][1,3,4][1,3,4] is also not a permutation (n=3n=3n=3 but there is 444 in the array).

The problem starts from here.

Link has an array. He is currently learning the longest increasing subsequence algorithm. So he comes up with the following question.

Let the value of a permutation ppp be max⁡(lis(p),lds(p))\max({\rm lis}(p),{\rm lds}(p))max(lis(p),lds(p)), where lis(p){\rm lis}(p)lis(p) is the length of the longest increasing subsequence of ppp and lds(p){\rm lds}(p)lds(p) is the length of the longest decreasing subsequence of ppp. For all permutations of length nnn, which one has the minimum value?
 

输入描述:


Each test contains multiple test cases. The first line contains the number of test cases T(1≤T≤1000)T(1\le T \le1000)T(1≤T≤1000).

For each test case, there is only one line, containing an integer n(1≤n≤106)n(1 \leq n \leq 10^6)n(1≤n≤106).

It is guaranteed that the sum of nnn over all test cases does not exceed 10610^6106.

输出描述:


For each test case, output a single line containing a permutation of length nnn.

If there are multiple answers, print any of them.

示例1

输入

复制3 1 2 3

3
1
2
3

输出

复制1 1 2 1 3 2

1
1 2
1 3 2

思路:

1,打表,找到符合题意的解,发现value和sqrt(n)有关

2,3 2 1 6 5 4 9 8 7,这样的话,分sqrt(n)块,块内减,块间递增,value是sqrt(n)。

代码:

void solve(){
    int n;cin>>n;
    int cnt=ceil(sqrt(n));
    vector<int>ve;
    int now=cnt,pre=1;
    rep(i,1,n){
        ve.emplace_back(now--);
        if(ve.size()==cnt){
            for(auto j:ve)cout<<j<<' ';
            ve.clear();
            now=min(++pre*cnt,n);
        }
    }
    for(auto i:ve)cout<<i<<' ';
    cout<<'\n';
    
}

标签:nnn,permutation,Monotonic,lds,Subsequence,Link,lis,test,rm
From: https://blog.csdn.net/m0_63054077/article/details/125961619

相关文章

  • 【阻抗建模、验证扫频法】光伏并网逆变器扫频与稳定性分析(包含锁相环电流环)(Simulink
    ......
  • Flink CEP (四)组合模式
    FlinkCEP(四)组合模式文章目录初始模式(InitialPattern)近邻条件(ContiguityConditions)严格近邻(StrictContiguity)宽松近邻(RelaxedContiguity)非确定性宽松近邻(Non-DeterministicRelaxedContiguity)其他限制条件循环模式中的近邻条件定义好的个体模式,就可以尝试按一定......
  • 一文聊透 Flink 的 Temporal Join
    博主历时三年精心创作的《大数据平台架构与原型实现:数据中台建设实战》一书现已由知名IT图书品牌电子工业出版社博文视点出版发行,点击《重磅推荐:建大数据平台太难了!给我发个工程原型吧!》了解图书详情,京东购书链接:https://item.jd.com/12677623.html,扫描左侧二维码进入京东手......
  • CF1922E Increasing Subsequences
    一个显然的思路就是构造很多互不相关的上升序列。但是这样构造出来的\(n\)是\(O(\log_2^2n)\)量级的,所以需要考虑新做法。假设我们本来有一个上升序列,我们能否往里面插数?如果插入的数前面本来有\(x\)个数,那么它有\(2^x\)的贡献。于是容易想到先写一个最大的上升序列,再二......
  • 2023-12-22-flink-cdc使用
    应用场景、上手体验应用场景FlinkCDC(ChangeDataCapture)是一种用于捕获和处理数据源中的变化的流处理技术。它可以实时地将数据源中的增量更新捕获到流处理作业中,使得作业可以实时响应数据变化。以下是FlinkCDC的一些常见应用场景:数据仓库和实时分析:FlinkCDC可以......
  • ArrayList的扩容机制以及ArrayList与LinkedList的区别
    ArrayList的扩容机制假设采用无参构造器来实列化ArrayList对象ArrayListarrayList=newArrayList();此时,arrayList的初始容量为零,当第一次调用add方法时,会触发扩容机制,容量扩容为10。此后,在调用add方法时,如果容量不足,则容量会扩容为当前容量的1.5倍。capcity=capacity......
  • 【阻抗建模、验证扫频法】光伏并网逆变器扫频与稳定性分析(包含锁相环电流环)(Simulink
    ......
  • find symbolic links
    -P永远不要跟随符号链接。这是默认行为。当find检查或打印有关文件的信息时,如果该文件是符号链接,则所使用的信息应从符号链接本身的属性中获取。 -L遵循符号链接。当find检查或打印有关文件的信息时,所使用的信息应取自链接指向的文件的属性,而不是链接本身(除非它是一个断开的......
  • Flink实战之Flink乱序场景汇总
    目录一数据乱序场景1数据源乱序2ETL造成乱序二Flink处理乱序数据方案1Watermark和EventTime模式2提前创建保序任务3使用事务性Sink保证下游数据时序三结语       在数据处理领域,无论离线批处理领域还是实时流处理领域,数据时序性对于最终数据的......
  • daplink烧录上位机
    前言daplink是个好东西,又便宜又好用,还不担心盗版,但是没有stlink和jlink那样的上位机可以直接下载固件,这就很头疼了。怎么办?还好通过jtag/sw协议下载固件有很多开源的项目项目介绍openOCD大名鼎鼎的openOCD(上手难度太高了,pass)python写的pyOCDOpensourcePythonlibraryf......