[DP地狱训练]Pascal山脉
OJ题号:ZHOJ1055
思路:树状数组。
首先将数据离散化,然后用线段树维护小于当前高度的山峰已经出现过的数量。
#include<cstdio>
#include<cstring>
#include<algorithm>
const int N=,root=;
int n;
class FenwickTree {
private:
int val[N<<];
public:
FenwickTree() {
memset(val,,sizeof val);
}
int lowbit(const int x) {
return x&-x;
}
int query(int p) {
int ans=;
while(p) {
ans+=val[p];
p-=lowbit(p);
}
return ans;
}
void modify(int p) {
while(p<=n) {
val[p]++;
p+=lowbit(p);
}
}
};
FenwickTree tree;
int main() {
scanf("%d",&n);
int a[n+],b[n+];
for(int i=;i<=n;i++) {
scanf("%d",&a[i]);
b[i]=a[i];
}
std::sort(&b[],&b[n+]);
int ans[n+];
for(int i=;i<=n;i++) {
int t=std::lower_bound(&b[],&b[n+],a[i])-&b[];
ans[i]=tree.query(t-);
tree.modify(t);
}
for(int i=;i<=n;i++) printf("%d ",ans[i]);
printf("\n");
return ;
}
[DP地狱训练]Pascal山脉的更多相关文章
- 1636: Pascal山脉
1636: Pascal山脉 时间限制: 1 Sec 内存限制: 128 MB提交: 51 解决: 15[提交][状态][讨论版] 题目描述 小卡卡顺着老者所指的方向,来到了Pascal神峰的顶峰 ...
- DP专题训练之HDU 2955 Robberies
打算专题训练下DP,做一道帖一道吧~~现在的代码风格完全变了~~大概是懒了.所以.将就着看吧~哈哈 Description The aspiring Roy the Robber has seen a ...
- dp专题训练
****************************************************************************************** 动态规划 专题训练 ...
- DP专题训练之HDU 1087 Super Jumping!
Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is ve ...
- DP专题训练之HDU 1231 最大连续子序列
Description 给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i <= j < ...
- DP专题训练之HDU 1864 最大报销额
做DP一定要注意数组的大小,嗯,就是这样~ Description 现有一笔经费可以报销一定额度的发票.允许报销的发票类型包括买图书(A类).文具(B类).差旅(C类),要求每张发票的总额不得超过10 ...
- 【Tensorflow】 Object_detection之训练PASCAL VOC数据集
参考:Running Locally 1.检查数据.config文件是否配置好 可参考之前博客: Tensorflow Object_detection之配置Training Pipeline Ten ...
- dp周训练 状态压缩
题目链接:题意:给你一个10*10的矩阵,每到一个格子中都要拿一个0-9的数值,求从矩阵左上方走到右下方且必须0-9都经过,拿的数值和最小是多少: #include <iostream> ...
- yolo3使用darknet卷积神经网络训练pascal voc
darknet本来最开始学的是https://github.com/pjreddie/darknet yolo3作者自己开发的,但是它很久不更新了而且mAP值不好观察,于是另外有个https://gi ...
随机推荐
- Child Process模块
目录 exec() execSync() execFile() spawn() fork() send() 参考链接 child_process模块用于新建子进程.子进程的运行结果储存在系统缓存之中( ...
- Maven介绍及安装与配置
一.Maven的作用 在开发中,为了保证编译通过,我们会到处去寻找jar包,当编译通过了,运行的时候,却发现"ClassNotFoundException",我们想到的是,难道还差 ...
- 重装windows系统后配置Anaconda
给电脑换了系统,十分担心anaconda需要重装.还好以下方法完美解决.(同是win10 64位) 原始anaconda安装路径:D:\ProgramData\Anaconda3 (不能有空格哦) ...
- 560. Subarray Sum Equals K
Given an array of integers and an integer k, you need to find the total number of continuous subarra ...
- Python-HTML CSS 练习
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- python与redis
1.什么是redis Redis 是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset ...
- C <string.h>常用函数介绍
1. strcpychar *strcpy(char *destin, char *source);功能:将source指向的字符串拷到destin. int main() { ]; "; ...
- mysql8.0CTE实现递归查询
+----+----------+--------------+| ID | ParentID | name |+----+----------+--------------+| 1 ...
- ubuntu 电源管理
https://www.cnblogs.com/sky-heaven/p/4561374.html?tdsourcetag=s_pcqq_aiomsg 挂起命令 echo mem > /sys ...
- 关系操作符 == != equals()
== 和!= //: object/test.java package object; import java.util.*; public class Test{ public static vo ...