随笔分类 - 线段树、树状数组、分块
摘要:1 /* 2 set 自带的 lower_bound 和 upper_bound 的时间复杂度为 O(logn)。 3 4 但使用 algorithm 库中的 lower_bound 和 upper_bound 函数对 set 中的元素进行查询,时间复杂度为 0(n)。 5 6 总结:对于可随机访问
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=200200; 5 int dep[N],fa[N][30],color[N],bin[N],blg[N],ord[N],in
阅读全文
摘要:最坑的是输入除了'Q','R'还有其他字母; 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=1e6+5; 5 int color[N],blg[N],cnt[N],ans[
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=2e5+5; 5 int n,m,p,l=1,r=0,tot=0; 6 ll blg[N],suff[N],bin[N],f[
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=5e4+5; 5 ll a[N],blg[N],cnt[N]; 6 string ans[N]; 7 inline ll gc
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=1e5+5; 5 vector<ll>v[N]; 6 ll a[N],tag[N],blg[N],L[N],R[N],bloc
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=5e4+5; 5 vector<ll>v[50005]; 6 ll a[N],tag[N],blg[N],L[N],R[N],
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=5e4+5; 5 int blg[N],L[N],R[N],tag[N],sum[N],a[N],block,tot; 6 v
阅读全文
摘要:1 #include<iostream> 2 #include<cstdio> 3 #include<vector> 4 #include<cstring> 5 #define ls (x<<1) 6 #define rs (x<<1|1) 7 using namespace std; 8 cons
阅读全文
摘要:Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 48841 Accepted: 14278 Description There is an apple tree outside of kaka's house
阅读全文
摘要:Tunnel Warfare Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 10964 Accepted: 4538 Description During the War of Resistance Against Japan
阅读全文
摘要:考虑如果顺序模拟会T,注意到最后一个元素一定在它确定的位置,考虑从后往前放,找第k个空位,完美解决这题; 1 #include<iostream> 2 #include<cstdio> 3 #define ls (x<<1) 4 #define rs (x<<1|1) 5 using namespa
阅读全文
摘要:P5490 【模板】扫描线 这题线段树的节点表示的是区间,树上节点x表示的区间【l,r】是实际点的[l,r+1]区间;因为我们纯用点一一对应 当标记落到一个点时 没有任何意义;标记更新,如果当前节点被标记,说明区间被标记,如果当前节点没被标记,返回左节点和右节点被标记的总长度 sum[x]维护的是节
阅读全文
摘要:1 #include<bits/stdc++.h> 2 #define ls (x<<1) 3 #define rs (x<<1|1) 4 #define rep(i,a,b) for(int i=a;i<=b;i++) 5 #define pb(a) push_back(a) 6 using na
阅读全文
摘要:这题是线段树的区间加、区间修改和懒标记,注意开long long 1 #include<bits/stdc++.h> 2 #define ls (x<<1) 3 #define rs (x<<1|1) 4 #define rep(i,a,b) for(int i=a;i<=b;i++) 5 #def
阅读全文
摘要:最近在看树状数组和线段树,没完整看完,把目前学的暂时记录,后续再补。 线段树和树状数组都是对区间操作的数据结构 1 #define ls (x<<1) 2 #define rs (x<<1|1) 3 using namespace std; 4 const int N=1e5+5; 5 int su
阅读全文