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. RPC架构下org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

    一.调用后台接口报错 网上有很多作者列出大部分原因: 1.实体类名对应配置文件名或者路径不一致 2.spring扫描路径不全 但是本人使用的是mtbatis逆向工程生成的实体类.接口与配置文件,所以不 ...

  2. MyBatis一级缓存的笔记及记录

    精髓内容来源于<图灵学院> 一.概述: 一级缓存是MyBatis天然自带的,是默认开启且没有关闭的地方,1级缓存只能作用于查询回话中,所以也叫会话缓存: 这里举个例子: 订单表存在一对多的 ...

  3. HDU-5155 Harry And Magic Box

    题目描述 在\(n*m\)的矩阵内每一行每一列都有钻石,问钻石分布的种类? 答案有可能很大,所以输出答案对\(1000000007\)取模. Input 对于每个测试用例,有两个整数\(n\)和\(m ...

  4. Python和mysql的连接

    python与mysql的连接: 说明:前提是已近安装了mysql以及可视化工具(本人装的是Navicat) 1.在cmd下下载Python的第三方数据库包:pip install pymysql: ...

  5. 2019长安大学ACM校赛网络同步赛 L XOR (规律,数位DP)

    链接:https://ac.nowcoder.com/acm/contest/897/L 来源:牛客网 XOR 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...

  6. 深度学习优化器 optimizer 的选择

    网址:https://blog.csdn.net/g11d111/article/details/76639460

  7. C#文件压缩成.Zip

    使用的三方类库ICSharpCode.SharpZipLib.dll 方法如下: /// <summary> /// 压缩文件为zip格式 /// </summary> /// ...

  8. Nginx 502 Bad Gateway 的错误的解决方案

    我用的是nginx反向代理Apache,直接用Apache不会有任何问题,加上nginx就会有部分ajax请求502的错误,下面是我收集到的解决方案. 一.fastcgi缓冲区设置过小 出现错误,首先 ...

  9. docker python3环境搭建

    1.使用镜像为daocloud的python镜像 docker run -it --rm --name my-running-script -v "$PWD":/usr/src/m ...

  10. Eclipse中对一个项目进行复制粘贴为一个新项目

    1:对目标项目执行右键,选择“Copy”,然后在空白处右键,选择“Paste”结果如下图: 2:右键新项目,点击Properties, 3:打开Navigator视图 4:打开.settings文件夹 ...