1208D Restore Permutation
题目大意
给你一个序列s
让你求一个1~n的序列
使得对于第i个位置它前面所有小于p[i]的数的和恰好为s[i]
分析
我们可以从后往前确定每一位
每次一二分找到恰好等于s[i]的数
但是我们发现这样会产生重复选一个点的情况
所以我们改为每次找第一个大于s[i]的点
这个点-1恰好为答案
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define int long long
int d[],n,s[],a[];
inline int lb(int x){return x&(-x);}
inline void add(int x,int k){while(x<=n)d[x]+=k,x+=lb(x);}
inline int q(int x){int res=;while(x)res+=d[x],x-=lb(x);return res;}
signed main(){
int i,j,k;
scanf("%lld",&n);
for(i=;i<=n;i++)scanf("%lld",&s[i]);
for(i=;i<=n;i++)add(i,i);
for(i=n;i>;i--){
int le=,ri=n,ans;
while(ri-le>){
int mid=(le+ri)>>;
if(q(mid)<=s[i])le=mid;
else ri=mid;
}
a[i]=ri;
add(a[i],-a[i]);
}
for(i=;i<=n;i++)printf("%lld ",a[i]);
puts("");
return ;
}
1208D Restore Permutation的更多相关文章
- [Codeforces 1208D]Restore Permutation (树状数组)
[Codeforces 1208D]Restore Permutation (树状数组) 题面 有一个长度为n的排列a.对于每个元素i,\(s_i\)表示\(\sum_{j=1,a_j<a_i} ...
- D. Restore Permutation(权值线段树)
D. Restore Permutation time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- D. Restore Permutation
D. Restore Permutation 就是给一个n个数的全排,然后bi记录比ai小且在排在ai前面的数的和,求ai 树状数组维护,二分 #include<bits/stdc++.h> ...
- D. Restore Permutation 树状数组+二分
D. Restore Permutation 题意:给定n个数a[i],a[ i ]表示在[b[1],b[i-1]]这些数中比 b[i]小的数的和,要你构造这样的b[i]序列 题解:利用树状数组 求比 ...
- 线段树维护最后一个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序列. 思路: 首 ...
- [CF1208D] Restore Permutation
传送门 题意:有一个长为\(n\)的排列\(p\),设\(S_i=\sum_{j=1}^{i-1}p_j\cdot[p_j<p_i]\),给出\(S\),要求还原出\(p\).保证有解,\(n\ ...
- cf1208 D Restore Permutation (二分+树状数组)
题意 让你构造一个长度为n的序列,记为p1……pn,(这个序列是1~n的全排列的一种) 给你n个数,记为s1……sn,si的值为p1……pi-1中小于pi的数的和. 思路 显然,应该倒着来,也就是从p ...
- CSU-ACM2020寒假集训比赛2
A - Messenger Simulator CodeForces - 1288E 两种解法,我选择了第二种 mn很好求,联系过就是1,没联系过就是初始位置 第一种:统计同一个人两次联系之间的出现的 ...
- 一句话CF
目录 \(\bf {Round \ \#500 \ (Div. \ 1)}\) \(\bf {Round \ \#589 \ (Div. \ 2)}\) \(\bf {Avito \ Cool \ C ...
随机推荐
- mooc-IDEA 项目/文件之间跳转--002
二.IntelliJ IDEA -项目之间跳转 1.Next Project Window :跳转到下一个项目 [ ctrl+alt+) ] 2.Previous Project Window:跳转到 ...
- 前端 CSS的选择器 伪元素选择器
介绍常用的伪元素. after用得比较多的 first-letter 用于为文本的第一个首字母设置样式. <!DOCTYPE html> <html lang="en&qu ...
- g50打开无线设置 fn+f7
- Codeforces 1042C (贪心+模拟)
题面 传送门 分析 思路简单,但代码较复杂的贪心 分类讨论: 有0 负数有奇数个:将绝对值最小(实际最大)的负数和0全部乘到一起,最后删掉0 负数有偶数个:将0全部乘到一起,最后删掉0 没有0 负数有 ...
- HDU-2571 命运(搜索,我才不是为了插图呢!哼!)
看到这题其实感觉就是搜索题,广搜的话看讨论区里已经有人内存超限了,所以我选择了深搜,有两种思路,第一种是从起点出发,依次更新每一个格子的最大值,这样dp[n][m]就是最后的结果了,第二种是从起点试探 ...
- [译]深度学习(Yann LeCun)
深度学习 严恩·乐库 约书亚•本吉奥 杰弗里·希尔顿 摘要深度学习是计算模型,是由多个处理层学习多层次抽象表示的数据.这些方法极大地提高了语音识别.视觉识别.物体识别.目标检测和许多其他领域如药物 ...
- Centos7搭建日志服务器rsyslog+loganalyzer
一.系统环境 Rsyslog Server OS:CentOS 7 Rsyslog Server IP:172.28.194.118 Rsyslog Version: rsyslog-7.4.7-12 ...
- php session生存周期
今天在我的微博(Laruence)上发出一个问题: 我在面试的时候, 经常会问一个问题: “如何设置一个30分钟过期的Session?”, 大家不要觉得看似简单, 这里面包含的知识挺多, 特别适合考察 ...
- kettle 通过JDBC 连接SQL Server(Error occurred while trying to connect to the database)
在连接数据(MS SQLServer 2008)发现:Error occurred while trying to connect to the database 然后找资料看,都不是问题所在,最后一 ...
- nginx主配置文件学习,以及nginx的反向代理和负载均衡
1.nginx.conf主配置文件学习 worker_processes : 表示nginx的进程数,根据CPU的核数来定义,起到优化的作用.通过cat /proc/cpuinfo来查看核数 even ...