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的更多相关文章

  1. [CF1208D] Restore Permutation

    传送门 题意:有一个长为\(n\)的排列\(p\),设\(S_i=\sum_{j=1}^{i-1}p_j\cdot[p_j<p_i]\),给出\(S\),要求还原出\(p\).保证有解,\(n\ ...

随机推荐

  1. 使用ef core自动生成mysql表和数据编码的问题

    mysql默认的编码是不支持中文的,需要改成utf8编码格式. 而我使用的Pomelo.EntityFrameworkCore.MySql组件生成mysql库和表,他是使用默认编码的. 网上大多说修改 ...

  2. Bat 批处理启动和停止Oracle 服务

    实际情况 * 不想开机自启动oracle服务,因为Windows 没有固态硬盘本身启动就很慢了,然后也不想自己手动的方式去启东oracle 服务 解决方案 *1启动 ``` @echo off ech ...

  3. Deep Learning方向的paper

    转载 http://hi.baidu.com/chb_seaok/item/6307c0d0363170e73cc2cb65 个人阅读的Deep Learning方向的paper整理,分了几部分吧,但 ...

  4. K最近邻算法项目实战

    这里我们用酒的分类来进行实战练习 下面来代码 1.把酒的数据集载入到项目中 from sklearn.datasets import load_wine #从sklearn的datasets模块载入数 ...

  5. 关于困惑已久的var self=this的解释

    首先说下this这个对象的由来(属于个人理解):每个函数在定义被ECMAScript解析器解析时,都会创建两个特殊的变量:this和arguments,换句话说,每个函数都有属于自己的this对象,这 ...

  6. 异常信息:javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed

    上周五遇到一个问题,工程本地编译运行正常,打包本地tomcat运行也正常.部署到测试环境报错: 2017-05-05 09:38:11.645 ERROR [HttpPoolClientsUtil.j ...

  7. vue的自定义指令

    点击元素之外触发函数 <template> <div v-clickoutside="clickItemOut"></div> </tem ...

  8. 不常见的sql错误处理方法(1)

    select @@global.sql_mode, mysql5.7 导致 group查询出错 set @@global.sql_mode='' # mysql重启就失效了: phpstudy -&g ...

  9. 【leetcode】566. Reshape the Matrix

    原题 In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a ne ...

  10. DAY1注册店铺