随笔分类 - 线段树
摘要:长度为n的直线上有几个防御塔,每个防御塔都有攻击范围为[L,R],然后给出几个怪物的血量和出现位置,问能从出现位置走到末尾的有几个。对于每次输入的防御塔的L,R和他的攻击力d,a[L]+=d,a[R+1]-=d。然后从1到n累加一遍计算出每个位置的实际伤害。最后从末尾累加到开始计算后缀和。#incl...
阅读全文
摘要:给定一个序列,求出一共有多少个三元组(ai,aj,ak),使得i#include #define maxn 100200#define N 20100int sum[maxn*4];int lmax[N],lmin[N],rmax[N],rmin[N];int ans[N];void pushup(...
阅读全文
摘要:题意:1 a:询问是不是有连续长度为a的空房间,有的话住进最左边2 a b:将[a,a+b-1]的房间清空#include #define maxn 51000int sum[4*maxn],lsum[4*maxn],rsum[4*maxn];int vis[4*maxn];int max(int ...
阅读全文
摘要:注意到当一个数开方到1后就不再变了,每个数开方次数不会太多,所以进行更新时如果该区间的数字都是1了就直接return#include #include #include #define maxn 100100__int64 sum[4*maxn];void build(int l,int r,int...
阅读全文
摘要:线段树的区间加减数,区间查询#include #include using namespace std;#define LL __int64const int maxn = 100100;LL sum[4*maxn];LL add[4*maxn];void build(int l,int r,int...
阅读全文
摘要:以高为数轴,维护每个区间的剩余最大值,用线段树二分做#include #define maxn 200100int Max[4*maxn];int h,w,n;int max(int a,int b){ if(a>b) return a; else return b;}void buil...
阅读全文
摘要:线段树的区间修改#include #define maxn 100100 int set[4*maxn],sum[4*maxn];void push(int o,int m){ if(set[o]) { set[2*o]=set[2*o+1]=set[o]; sum[2*...
阅读全文
摘要:代码出自http://www.notonlysuccess.com/index.php/segment-tree-complete/#include #include using namespace std;#define lson l , m , rt > 1; build(lson); ...
阅读全文
摘要:#include #include #define N 200200int max[4*N];int n,m;int A,B;int L,R;int MAX(int a,int b){ if(a>b) return a; else return b;}int MIN(int a,int b){ if...
阅读全文

浙公网安备 33010602011771号