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 ...
随机推荐
- [10期]浅谈SSRF安全漏洞
引子:SSRF 服务端请求伪造攻击 很多web应用都提供从其他服务器上获取数据的功能.使用用户指定的URL,web应用可以从其他服务器获取图片,下载文件,读取文件内容等. 这个功能被恶意使用的话,可以 ...
- 【转载】如何编写ROS的第一个程序hello_world
目录 1.工作空间的创建 2.功能包的创建 3.功能包的源代码编写 4.功能包的编译配置 5.功能包的编译 6.功能包的启动运行 既然ROS已经成功安装好了,大家一定很想亲自动动手编一个通过起手式例程 ...
- <每日一题> Day3:CodeForces-1141B.MaximalContinuousRest(简单题)
题目链接 参考代码: #include <iostream> #include <algorithm> using namespace std; + ; int value[m ...
- 厉害了,Apache架构师们遵循的 30 条设计原则
作者:Srinath 翻译:贺卓凡,来源:公众号ImportSource Srinath通过不懈的努力最终总结出了30条架构原则,他主张架构师的角色应该由开发团队本身去扮演,而不是专门有个架构师团队或 ...
- node基本介绍及使用
1.什么是node 简单的说node.js就是运行在服务端的JavaScript 官网地址:http://nodejs.cn/ 2.node安装 2.1下载node node下载:https://no ...
- Codeforces 609E (Kruskal求最小生成树+树上倍增求LCA)
题面 传送门 题目大意: 给定一个无向连通带权图G,对于每条边(u,v,w)" role="presentation" style="position: rel ...
- 使用absolute实现的后台布局,包括小图标定位,菜单弹出等完整版
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- spark复习笔记(6):数据倾斜
一.数据倾斜 spark数据倾斜,map阶段对key进行重新划分.大量的数据在经过hash计算之后,进入到相同的分区中,zao
- vue-fiters过滤器的使用
1.定义过滤器 2.使用过滤器 ...... <el-table-column prop="user_gender" align="center" lab ...
- Git 安装使用及基础命令
Git终端软件安装 1.下载windows上git终端,类似shell工具,下载地址:http://msysgit.github.io/ 2. 安装方法,打开文件,一路点击Next即可 3.安装完成, ...