一个显然的思路就是构造很多互不相关的上升序列。但是这样构造出来的 \(n\) 是 \(O(\log_2^2 n)\) 量级的,所以需要考虑新做法。

假设我们本来有一个上升序列,我们能否往里面插数?如果插入的数前面本来有 \(x\) 个数,那么它有 \(2^x\) 的贡献。于是容易想到先写一个最大的上升序列,再二进制拆分即可。

#include <bits/stdc++.h>
using namespace std; long long read() {
char c = getchar();
long long x = 0, p = 1;
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') p = -1, c = getchar();
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return x * p;
} const int N = 207; long long x; void solve() {
x = read();
long long p = 1, k = 0;
while (p * 2 <= x) {
p *= 2;
k ++;
}
x -= p;
vector <int> bit;
int cnt = 0;
while (x) {
bit.push_back(x % 2);
cnt += (x % 2 == 1); x /= 2;
}
cout << cnt + k << '\n';
for (int i = 0, j = cnt + k; i <= k; i ++) {
if (i > 0)
cout << i << ' ';
if (i < (int) bit.size() && bit[i])
cout << (j --) << ' ';
}
cout << '\n';
} signed main() {
int t = 1;
t = read();
while (t --) solve();
return 0;
}

CF1922E Increasing Subsequences的更多相关文章

  1. [LeetCode] Increasing Subsequences 递增子序列

    Given an integer array, your task is to find all the different possible increasing subsequences of t ...

  2. [Swift]LeetCode491. 递增子序列 | Increasing Subsequences

    Given an integer array, your task is to find all the different possible increasing subsequences of t ...

  3. 491. Increasing Subsequences增长型序列

    [抄题]: Given an integer array, your task is to find all the different possible increasing subsequence ...

  4. SnackDown Longest Increasing Subsequences 构造题

    Longest Increasing Subsequences 题目连接: https://www.codechef.com/SNCKPA16/problems/MAKELIS Description ...

  5. Leetcode之深度优先搜索&回溯专题-491. 递增子序列(Increasing Subsequences)

    Leetcode之深度优先搜索&回溯专题-491. 递增子序列(Increasing Subsequences) 深度优先搜索的解题详细介绍,点击 给定一个整型数组, 你的任务是找到所有该数组 ...

  6. [LeetCode] 491. Increasing Subsequences 递增子序列

    Given an integer array, your task is to find all the different possible increasing subsequences of t ...

  7. LeetCode 491. Increasing Subsequences

    原题链接在这里:https://leetcode.com/problems/increasing-subsequences/ 题目: Given an integer array, your task ...

  8. 【LeetCode】491. Increasing Subsequences 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  9. 491. Increasing Subsequences

    这种increasing xxx 题真是老客户了.. 本题麻烦点在于不能重复, 但是和之前的那些 x sum的题目区别在于不能排序的 所以.... 我还是没搞定. 看了一个Java的思路是直接用set ...

  10. Longest Increasing Subsequences(最长递增子序列)的两种DP实现

    一.本文内容 最长递增子序列的两种动态规划算法实现,O(n^2)及O(nlogn).     二.问题描述 最长递增子序列:给定一个序列,从该序列找出最长的 升序/递增 子序列. 特点:1.子序列不要 ...

随机推荐

  1. vue3 基础-应用app和组件基本概念

    这篇主要对 vue 最基础的应用程序 Application 和组件 Components 进行一个简要和直观的认知, 具体要分析的代码如下: <!DOCTYPE html> <ht ...

  2. SQL 强化练习 (九)

    这两天在写一个权限的sql, 涉及 3 张表, 然后做了一个 union all 的操作, 感觉效率有点问题, 写套娃, 改来改去的做优化. 关键数据又不能贴, 嗯, 还是明天搞个假数据来说明这个关系 ...

  3. OpenPPL的执行流程与类间关系UML表达

    上一讲,对OpenPPL进行了介绍,以及通过官方文档,学习了它的python与C++的操作流程,以及如添加新的引擎与Op算子. 本节,将通过阅读代码通过UML梳理操作流程以及类之间的相互关系 src地 ...

  4. lambdo表达式

    ************************************************************************* 原作者:ioriogami 原文:https://b ...

  5. TenantLineInnerInterceptor源码解读

    一.引言 TenantLineInnerInterceptor是MyBatis-Plus中的一个拦截器类,位于com.baomidou.mybatisplus.extension.plugins.in ...

  6. Windows平台调试器原理与编写05.内存断点

    https://www.bpsend.net/thread-274-1-3.html 内存断点 访问断点 写入断点 内存写入断点 简介:当被调试进程访问,读或写指定内存的时候,程序能够断下来. 思考1 ...

  7. Java面试题:浅谈Spring Bean的生命周期

    摘要:如果熟悉Spring 中 Bean的生命周期,可以加深对Spring的认知,故综述一下Bean的生命周期. 前言   Spring中Bean的生命周期是找工作的时候会被问到的高频面试题,主要用于 ...

  8. AdGuard Home使用体验

    AdGuard Home使用体验 AdGuard Home is a network-wide software for blocking ads and tracking. After you se ...

  9. gitlabci之gitlab runner部署配置

    gitlab runner部署 部署方案可以采用gitlab runner operator部署,也可以直接使用gitlab helm charts部署. runner配置说明 对于k8s gitla ...

  10. Linux系统配置windows可访问的共享文件夹

    一.简单说明 某些情况下,我们需要配置Linux系统的目录为共享文件夹,windows下可以直接访问.这里可以直接安装samba进行.(samba是一款软件,主要提供cifs协议,基于文件系统传输) ...