2017-10-07 17:54:55 writer:pprp /* @theme: 最基本的线段树 @writer:pprp @end:17:38 @attention:记录的数组应该从1开始,不能从0开始 */ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; +; const int INF = 0x3f3…
Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 53703   Accepted: 25237 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…
<题目链接> 题目大意: 求给定区间内最大值与最小值之差. 解题分析: 线段树水题,每个节点维护两个值,分别代表该区间的最大和最小值即可. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define Lson rt<<1,l,mid #define Rson rt<<1|1,mid+1,r #define INF 0x3f…
Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 32820   Accepted: 15447 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…
Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 42489   Accepted: 20000 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…
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 62103 Accepted: 29005 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 de…
题意:给出n个数,a1,a2,a3,---,an,再给出q次询问区间al到ar之间的最大值和最小值的差 学习线段树的第一道题目 学习的这一篇 http://www.cnblogs.com/kuangbin/archive/2011/08/14/2137862.html #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #in…
题意:求区间最大值-最小值. 分析: 1.线段树 #include<cstdio> #include<cstring> #include<cstdlib> #include<cctype> #include<cmath> #include<iostream> #include<sstream> #include<iterator> #include<algorithm> #include<st…
题目连接: http://poj.org/problem?id=3264 题目大意: 有n个数从1开始编号,问在指定区间内,最大数与最小数的差值是多少? 解题思路: 在节点中存储max,min,然后查询指定区间的max.min. #include <cstdio> #include <iostream> #include <algorithm> using namespace std; ; const int INF = 0x3f3f3f3f; struct node…
http://poj.org/problem?id=3264 题意:给你一个长度为n的序列a[N] (1 ≤ N ≤ 50000),询问Q(1 ≤ Q ≤ 200000) 次,每次输出[L, R]区间最大值与最小值的差是多少. 只需把模板的求和改成求最大和最小即可 #include <string.h> #include <algorithm> #include <stdio.h> #include <math.h> #include <queue&g…