![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
树状数组
Jerry99s
OI -> ACM -> AI
展开
-
LA 4329 - Ping pong
题目:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2330 http://poj.org/problem?id=3928 分析:树状数组 代码:#include <cstdio>#include <algori原创 2015-06-13 21:51:45 · 394 阅读 · 0 评论 -
洛谷2448 无尽的生命
题目:http://www.luogu.org/problem/show?pid=2448 分析:首先离散化,然后树状数组求所有操作过的数产生的逆序对,再求每个操作过的数与没操作过的数产生的逆序对,因为原始序列有序,所以很方便。 代码:#include <cstdio>#include <iostream>#include <algorithm>#include <map>using n原创 2015-10-02 22:06:21 · 540 阅读 · 0 评论 -
BestCoder#56 Clarke and puzzle
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5465 分析:由上一篇博客可之,xor为0则先手必输。所以只需一个二维树状数组。 代码:#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int Tmax=505;int n,m,q;原创 2015-09-22 21:17:01 · 347 阅读 · 0 评论 -
HDU4006 The kth great number
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4006 分析:查询第k大,其中一做法是二分+树状数组,复杂度是log^2(n),还有一种是树状数组logn。 代码:#include <cstdio>#include <algorithm>#include <cstring>#include <map>using namespace std;c原创 2015-11-02 14:38:31 · 310 阅读 · 0 评论 -
树状数组-单点修改区间查询-区间修改单点查询-区间修改区间查询
单点修改区间查询: HDU1166#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int Tmax=50005;int n,c[Tmax];char s[10];int lowbit(int x){ return x&-x;}int sum(int x){原创 2017-10-07 21:12:02 · 367 阅读 · 0 评论 -
CF#450 C.Remove Extra One
题目:http://codeforces.com/problemset/problem/900/C 分析: n是1e5,所以应该是一个nlogn的数据结构; 考虑删除一个数ai,会增加多少个record number? 假设aj变成了record number,那么aj满足aj < ai并且aj > ak(k=1,2,3,..,i-1); ①所以用v[i]=true表示确实存在且仅有一个a原创 2017-12-12 12:15:17 · 453 阅读 · 0 评论 -
HDU 6318 Swaps and Inversions (树状数组求逆序对)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6318题意: 可以x元直接交换一对逆序对 可以y元交换两个相邻元素 求最小花费分析: 为了花费最少,交换的两个相邻元素一定也为逆序对; 所以x,y两种操作,每次均消除一对逆序对; 那么,求所有逆序对数ans,答案即为ans*min(x,y);先离散化,用树状数组求逆序对即可,注意处理...原创 2018-08-03 09:58:26 · 202 阅读 · 0 评论 -
HDU 6315 Naive Operations (2018多校第2场1007) (线段树+树状数组)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6315题意: 给定一个序列b[i]; 数列a[i]初始全0; 每次操作可以向a中[l,r]区间+1; 每次求分析: 首先将线段树中第i位赋值为b[i],代表i位需要加b[i]次才会对答案+1; 每次区间加操作,认为是对区间-1; 用线段树记录区间最小值及最小值出现的位置; 若区间最小...原创 2018-08-03 15:23:10 · 168 阅读 · 0 评论