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. Maven - Maven3实战学习笔记(1)Maven使用入门

    1.maven安装 1>http://maven.apache.org/download.cgi下载apache-maven-3.6.1 2>解压缩安装包到指定的文件夹,如C:\fyliu ...

  2. C#杀进程与之之子进程

    using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using S ...

  3. java中<<,>>和>>>的含义

    <<,>>,>>>为java中的移位运算符. <<表示左移运算符 例如8<<2,表示将8向左移2位,结果为32.低位补0. 二进制演算 ...

  4. 在window环境下安装symfony2框架注意事项

    首先先放上放上安装的教程:http://www.symfonychina.com/doc/current/setup.html 然后说一下笔者遇到的坑 在运行这条命令的时候,虽然成功下载读取下来了,但 ...

  5. 关于ftp无法链接的情况

    首先查看ftp是否安装 systemctl status vsftpd 如果没有先安装 yum install vsftpd 然后启动 systemctl start vsftpd 如果有报错 Job ...

  6. Jmeter分布式测试dubbo接口2

    上次我们将dubbo接口与jmeter集成起来,但是jmeter是由java实现的,本身有很多限制,无法实现高并发,我们需要借助分布式来实现大压力测试. 在上次的例子中,我们只是实现了简单的dubbo ...

  7. mysql5.7.26做主从复制配置

    一.首先两台服务器安装好mysql数据库环境 参照linux rpm方式安装mysql5.1 https://www.cnblogs.com/sky-cheng/p/10564604.html 二.主 ...

  8. Big Data(二)分布式文件系统那么多,为什么hadoop还需要一个hdfs文件系统?

    提纲 - 存储模型- 架构设计- 角色功能- 元数据持久化- 安全模式- 副本放置策略- 读写流程- 安全策略 存储模型 - 文件线性按字节切割成块(block),具有offset,id - 文件与文 ...

  9. HelloWorld的解析

    public class HelloWorld { public static void main(String[] args) { System.out.println("你好,世界!&q ...

  10. app 进入后台进行模糊处理

    金融类app防止信息在后台中被一些恶意截屏软件进行截屏,对进入后台的app做模糊处理 - (void)applicationWillResignActive:(UIApplication *)appl ...