D. Restore Permutation

就是给一个n个数的全排,然后bi记录比ai小且在排在ai前面的数的和,求ai
树状数组维护,二分
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define si signed
#define endl '\n'
#define sc(x) scanf("%I64d",&x);
#define read(A) for(int i=1;i<=n;i++)scanf("%I64d",&A[i]);
#define P pair<int,int>
#define fi first
#define se second
#define ot(x) cout<<x<<'\n';
#define maxn 200000+500
int A[maxn];
int n,t,x,y,a,b;
int c[maxn];
int ans[maxn];
bool B[maxn];
int lowbit(int x)
{
return x&(-x);
} void add(int i,int k)
{
while(i <= n+)
{
c[i] += k;
i += lowbit(i);
}
} int get(int i)
{ int res = ;
while(i > )
{
res += c[i];
i -= lowbit(i);
}
return res;
}
int solve(int x)
{ int l=,r=n;
int mid;
while(l+<r)
{
mid=(l+r)/;
if(get(mid-)<=x){
l=mid;
}else if(get(mid-)>x){
r=mid-;
}
}
int ans;
if(get(r-)==x){
ans=r;
}else ans=l; return ans;
}
signed main()
{
sc(n); for(int i=;i<=n;i++){
sc(A[i]);
add(i,i);
}
//
int _j=; for(int i=n; i>; i--)
{
if(A[i]==)
{
for(_j; _j<=n; _j++)
{
if(!B[_j])
{
ans[i]=_j;
add(_j,-_j);
B[_j]=;
break;
}
}
}
else
{
ans[i]=solve(A[i]);
B[ans[i]]=;
// cout<<ans[i]<<'\n';
add(ans[i],-ans[i]);
}
}
for(int i=; i<=n; i++)
{
cout<<ans[i]<<' ';
} }

D. Restore Permutation的更多相关文章

  1. D. Restore Permutation(权值线段树)

    D. Restore Permutation time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. [Codeforces 1208D]Restore Permutation (树状数组)

    [Codeforces 1208D]Restore Permutation (树状数组) 题面 有一个长度为n的排列a.对于每个元素i,\(s_i\)表示\(\sum_{j=1,a_j<a_i} ...

  3. D. Restore Permutation 树状数组+二分

    D. Restore Permutation 题意:给定n个数a[i],a[ i ]表示在[b[1],b[i-1]]这些数中比 b[i]小的数的和,要你构造这样的b[i]序列 题解:利用树状数组 求比 ...

  4. 线段树维护最后一个0的位置(Restore Permutation)Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)

    题意:https://codeforc.es/contest/1208/problem/D 给你长度为n的序列,s[i]的值为p[1]到p[i-1]中比p[i]小的数的和,让你求出p序列. 思路: 首 ...

  5. [CF1208D] Restore Permutation

    传送门 题意:有一个长为\(n\)的排列\(p\),设\(S_i=\sum_{j=1}^{i-1}p_j\cdot[p_j<p_i]\),给出\(S\),要求还原出\(p\).保证有解,\(n\ ...

  6. 1208D Restore Permutation

    题目大意 给你一个序列s 让你求一个1~n的序列 使得对于第i个位置它前面所有小于p[i]的数的和恰好为s[i] 分析 我们可以从后往前确定每一位 每次一二分找到恰好等于s[i]的数 但是我们发现这样 ...

  7. cf1208 D Restore Permutation (二分+树状数组)

    题意 让你构造一个长度为n的序列,记为p1……pn,(这个序列是1~n的全排列的一种) 给你n个数,记为s1……sn,si的值为p1……pi-1中小于pi的数的和. 思路 显然,应该倒着来,也就是从p ...

  8. 一句话CF

    目录 \(\bf {Round \ \#500 \ (Div. \ 1)}\) \(\bf {Round \ \#589 \ (Div. \ 2)}\) \(\bf {Avito \ Cool \ C ...

  9. Manthan Codefest 19 题解

    这套题还是有点质量的吧 -- 题目链接 A. XORinacci 傻叉签到题,因为异或的性质所以这个序列的循环节长度只有 \(3\) -- 查看代码 B. Uniqueness 因为序列长度乃至数的种 ...

随机推荐

  1. python 序列 转换 各种操作

    # 数据结构 字符串 列表 元组 数字序列# 10-19的整数# r1 = range(10,20)# print(r1)# print(type(r1))## # 19# print(r1[9])# ...

  2. [LeetCode] 227. 基本计算器 II

    题目链接: https://leetcode-cn.com/problems/basic-calculator-ii 难度:中等 通过率:33.2% 题目描述: 实现一个基本的计算器来计算一个简单的字 ...

  3. nginx正常启动,ip直接访问失败问题

    1.查看iptables服务示范启动 service iptables status 2.没有安装的话安装 yum install iptables-services 3.修改配置文件, 添加一行: ...

  4. npm学习(九)之README.md文件

    包括文档(readme.md) npm建议您包含一个readme文件来记录您的包.自述文件必须有文件名readme.md.文件扩展名.md表示该文件是一个标记(markdown)文件.当有人发现您的包 ...

  5. tp5+layui实现分页

    layui和thinkphp5自己在百度上下载 html代码 <!DOCTYPE html> <html> <head> <meta charset=&quo ...

  6. iconv - 字符集转换

    总览 (SYNOPSIS) iconv [-f encoding] [-t encoding] [inputfile ...] 描述 (DESCRIPTION) iconv 程序 把 文本 从 一种 ...

  7. python-函数1(定义-作用-优势-返回值)

    python-函数1(定义-作用-优势-返回值) 1.面向对象的定义是靠-类>>class2.面向过程的定义是靠-过程 >>def3.函数式编程的定义是靠-函数>> ...

  8. mysql面试题练习01

    1.数学函数 有如下表和数组 把num值处于[20,29]之间,改为20 num值处于[30,39]之间的,改为30 ) ; 2.字符串 把good表中商品名为'诺基亚xxxx'的商品,改为'HTCx ...

  9. web框架-(五)Ajax

    Ajax即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术,AJAX = 异步 JavaScript和X ...

  10. 【vue2.x基础】用npm起一个完整的项目

    1. 安装vue npm install vue -g 2.  安装vue-cli脚手架 npm install vue-cli -g 3. 安装webpack npm install webpack ...