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. Spring(十)--Advisor顾问

    Spring之Advisor顾问 1. 创建新的xml文件  advisor.xml <!--01. 配置目标对象 实际肯定是配置UserServiceImpl--> <bean i ...

  2. 写 JSP 的痛点,真的非常痛!

    一.前戏 前后端分离已成为互联网项目开发的业界标准使用方式,通过nginx+tomcat的方式(也可以中间加一个nodejs)有效的进行解耦,并且前后端分离会为以后的大型分布式架构.弹性计算架构.微服 ...

  3. MySQL总结(5)

    视图 SELECT cust_name,cust_contact FROM customers,orders,orderitems WHERE customers.cust_id=orders.cus ...

  4. 在linux下和Mac下如何实现快捷方式连接SSH远程服务器

    其实特别简单 在本地命令执行目录/usr/local/bin 下新建一个shell脚本 比如 #vim ssh1 写入要执行的内容连接SSH #!/usr/bin/expect -f set user ...

  5. Fire Net HDU - 1045 (二分图匹配)

    题意: 给出一张图,图中'X'表示wall,'.'表示空地,可以放置blockhouse同一条直线上只能有一个blockhouse,除非有wall 隔开,问在给出的图中最多能放置多少个blockhou ...

  6. 剑指offer-二进制中1的个数-进制转化-补码反码原码-python

    题目描述 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示.   ''' 首先判断n是不是负数,当n为负数的时候,直接用后面的while循环会导致死循环,因为负数 向左移位的话最高位补1 ...

  7. js获取两个经纬度之间的角度(0度-360度)

    /** * 获取角度 */mapNumberUtil.getAngle = function(lng_a,lat_a, lng_b, lat_b){ var a = (90 - lat_b) * Ma ...

  8. xml的解析及案例的分析和分享

    HTML的文档如下: <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset=& ...

  9. pause模块

    pause模块:暂停脚本执行 # ansible-doc -s pause- name: Pause playbook execution pause: minutes: // 暂停的真实分钟数 pr ...

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

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