CF1208D
CF1208D
题意;
给你一个数组,要求支持单点修改和单点查询
解法:
直接线段树搞一搞就没了。
CODE:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define lson x << 1
#define rson x << 1 | 1
#define mid (l + r)/2
#define LL long long
using namespace std;
const int N = 200010;
struct Tree {
LL minv;
LL sum;
}tree[N * 4];
int n, m, p[N];
LL s[N];
void pushup(int x) {
tree[x].minv = min(tree[lson].minv, tree[rson].minv);
}
void pushdown(int x) {
if (tree[x].sum) {
tree[lson].sum += tree[x].sum;
tree[rson].sum += tree[x].sum;
tree[lson].minv += tree[x].sum;
tree[rson].minv += tree[x].sum;
tree[x].sum = 0;
}
}
void build(int x, int l, int r) {
if (l == r) {
tree[x].minv = s[l];
return;
}
build(lson, l, mid);
build(rson, mid + 1, r);
pushup(x);
}
void update(int x, int l, int r, int ll, int rr, int v) {
if (ll > rr)return;
if (l >= ll && r <= rr) {
tree[x].sum += v;
tree[x].minv += v;
return;
}
pushdown(x);
if (ll <= mid) update(lson, l, mid, ll, rr, v);
if (rr > mid) update(rson, mid + 1, r, ll, rr, v);
pushup(x);
}
int query(int x, int l, int r) {
if (l == r) {
tree[x].minv = 1e18;
return l;
}
pushdown(x);
int ans = 0;
if (tree[rson].minv == 0)
ans = query(rson, mid + 1, r);
else ans = query(lson, l, mid);
pushup(x);
return ans;
}
int main() {
scanf("%d",&n);
for(int i = 1; i <= n; i++)
scanf("%lld",&s[i]);
build(1, 1, n);
for(int i = 1; i <= n; i++) {
int x = query(1, 1, n);
p[x] = i;
update(1,1,n,x + 1,n,-i);
}
for(int i = 1; i <= n; i++)
printf("%d ",p[i]);
printf("\n");
return 0;
}
CF1208D的更多相关文章
- [CF1208D] Restore Permutation
传送门 题意:有一个长为\(n\)的排列\(p\),设\(S_i=\sum_{j=1}^{i-1}p_j\cdot[p_j<p_i]\),给出\(S\),要求还原出\(p\).保证有解,\(n\ ...
随机推荐
- 获取类的描述信息 DescriptionAttribute
static void Main(string[] args) { var attrs = typeof(TestClass).GetCustomAttributes(typeof(System.Co ...
- MarkDown 语法记录
Markdown是一种纯文本格式的标记语言.通过简单的标记语法,它可以使普通文本内容具有一定的格式. 为啥要用 MarkDown 呢? 优点 1.因为是纯文本,所以只要支持Markdown的地方都能获 ...
- 学习C#自作计算器,菜鸟初学,有大神的指点,希望做的不够好的地方请大家多多指导。同时希望非常无聊的大神能加些其它计算进去
可以做幂运算,根号运算,十进制与二进制互转,16进制与十进制互转 namespace WindowsFormsApplication15 { public partial class 祥哥计算器 : ...
- 解析Illumina+PacBio组装策略
解析Illumina+PacBio组装策略 (2016-12-08 13:21:58) 转载▼ 基于Illumina和PacBio平台的“二加三”组装策略,巧妙的融合了PacBio平台超长读长 ...
- 编译 recastnavigation
1. https://github.com/memononen/recastnavigation 下载zip并解压 2. 打开https://www.libsdl.org/download-2.0 ...
- 获取select标签的自定义属性
$("#ddlUsers").find("option:selected").attr("fullstr"); fullstr就是自定义属性 ...
- leetcode-63. Unique Paths II · DP + vector
题面 A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...
- libssh
1.SSH概念 ssh(secure shell),安全外壳协议,由IETF的网络小组所制定.ssh为建立在应用层基础上的安全协议.SSH是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议. ...
- 13 Windows编程——系统内置窗口子类型之静态子窗口
静态子窗口类型 wndclass:static 源码 #include<Windows.h> #include<Windowsx.h> HINSTANCE G_h; LRESU ...
- linux设置自动同步服务器时间
最近遇到一个问题,由于两台服务器时间的问题,经常导致用户登录由于时间差问题而报错,再三百度,最后整理了一下修改linux定时同步的操作(本方法适用于有自己时间服务器,没有的只限于借鉴) 首先确认,我们 ...