C++ 简单介绍线段树】的更多相关文章

题目描述 如题,已知一个数列,你需要进行下面两种操作: 将某区间每一个数加上k. 求出某区间每一个数的和. 输入格式 第一行包含两个整数n,m分别表示该数列数字的个数和操作的总个数. 第二行包含n个用空格分隔的整数,其中第i个数字表示数列第i项的初始值. 接下来m行每行包含3或4个整数,表示一个操作,具体如下: 1 x y k:将区间[x,y]内的数每个加上k. 2 x y:输出区间[x,y]内每个数的和. 输出格式 输出包含若干行整数,即为所有操作 2 的结果. 输入输出样例 输入 #1 复制…
An easy problem A Time Limit: 1000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Problem Description N个数排成一列,Q个询问,每次询问一段区间内的数的极差是多少. Input 第一行两个整数N(1≤N≤50000),Q(1≤Q≤200000).接下来一行N个整数a1 a2 a3 -.an,(1≤ai≤1000000000).接下来Q行,每行两个整数L,R(1≤L…
「CQOI2006」简单题 线段树 水.区间修改,单点查询.用线段树维护区间\([L,R]\)内的所有\(1\)的个数,懒标记表示为当前区间是否需要反转(相对于区间当前状态),下方标记时懒标记取反即可. #include <cstdio> #include <cmath> #define sl (x<<1) #define sr (x<<1|1) #define MAXN 100010 using namespace std; struct nod{ int…
Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 40687   Accepted: 19137 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer Joh…
同 HDU 2836 只不过改成了求最长子串. DP+线段树单点修改+区间查最值. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #define lson l, m, rt << 1 #define rson m + 1, r, rt << 1 | 1 using namespace std; ; int n, d; int v…
题意 题目链接 Sol 紫色的线段树板子题??... #include<iostream> #include<cstdio> #include<cmath> using namespace std; const int MAXN = 1e6 + 10; inline int read() { char c = getchar(); int x = 0, f = 1; while (c < '0' || c > '9') {if (c == '-')f = -…
题目链接:http://poj.org/problem?id=3468 题解:splay功能比线段树强大当然代价就是有些操作比线段树慢,这题用splay实现的比线段树慢上一倍.线段树用lazy标记差不多要2s用splay要4s.可以用splay来实现线段树的区间操作更深层次的了解一下splay算是入个门. #include <iostream> #include <cstring> #include <cmath> #include <cstdlib> #i…
http://acm.hdu.edu.cn/showproblem.php?pid=1556 Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色.但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?   Input 每个测试实例第一行为一个整数N,(N <= 100000…
Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 33389   Accepted: 15665 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to org…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 简单的线段树的应用 直接贴代码了: 代码: #include<iostream> #include<cstdlib> #include<cstdio> #include<cstring> #define maxn 100100 using namespace std; class node { public: int l; int r; int add;…