![](https://img-blog.csdnimg.cn/20190927151053287.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
树状数组、线段树
树状数组、线段树
梨小畅
这个作者很懒,什么都没留下…
展开
-
hdu1754 I Hate It
传送门思路裸题Code#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 200010;int w[N];int n,m;struct node{ int l,r; int maxm;}tr[N*4];void pushup(int u){ tr[u].maxm=max(tr[u<<1].maxm,tr[u<<原创 2021-09-01 15:12:10 · 80 阅读 · 0 评论 -
hdu1166 敌兵布阵
传送门思路裸题Code#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 50010;ll tr[N];ll ans[N];int n;int lowbit(int x){ return x & -x;}void add(int x,int v){ for(int i=x;i<=n;i+=lowbit(i)) tr[i]+=原创 2021-09-01 15:08:32 · 74 阅读 · 0 评论 -
P4113 [HEOI2012]采花
传送门思路类似于 HH的项链本题题意:问区间[L,R]里,出现次数 >= 2 的元素有几种不同之处在于本题需要维护两个lastlast1[i]:i 上一次出现的位置last2[i]:i 上上次出现的位置对于一个元素 x ,当它第一次出现时,什么都不发生,同时更新 last1当它的 last1[x] 存在时,在 last1[x] 位置上 加1,同时更新 last1 和 last2当它的 last2[x] 存在时,在 last1[x] 位置上 加1, 在 last2[x] 位置上 减1,原创 2021-08-23 18:35:55 · 68 阅读 · 0 评论 -
P1972 [SDOI2009]HH的项链
传送门思路题意概括:问 [L,R] 里,有多少种数字 ?在以 R 为右端点的区间里,对于某一种数字,我们只关心 它最后一次出现的位置我们只在其最后一次 出现的位置上 加 1 ( add 操作 ),其余出现的位置都保持为 0比如数列:1、3、3、1当 R = 4 时,进行 add 操作后,各位置上的数为 0、0、1、1此时,无论 左端点 L (L <= R)取值为多少,[L,R] 里的数字种类 都等于 sum(R)- sum(L - 1)对于 m 个询问,若每次都遍历询问区间 [Li,R原创 2021-08-22 23:59:01 · 56 阅读 · 0 评论 -
P3586 [POI2015]LOG
P3586 [POI2015]LOG思路显然,he >= (c-k)*s 时,输出 TAK,否则 NIEc 和 s 的含义如题目he 的含义:小于 s 的数 的和k 的含义:大于等于 s 的数 的数目问题转化为 快速求 he 和 k:使用树状数组显然 我们先需要离散化:将 m 个询问里的 a 和 s 进行离散化然后 维护两个树状数组:对于 k :我们可以维护一个树状数组 tradd(tr,x,v) 表示:让数字 x ,其数目 + vsum(tr,x) 表示:大小在 [1,x]原创 2021-08-22 18:00:37 · 173 阅读 · 0 评论