(线段树)Balanced Lineup --POJ --3264】的更多相关文章

链接: 对于POJ老是爆,我也是醉了, 链接等等再发吧! http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82832#problem/G 只是简单的建树,每个节点上记录它的最大值和最小值,最后查询一下,就ok了 代码: #include<cstdio> #include<cmath> #include<cstring> #include<cstdlib> #include<algorithm&…
题意 给出一个序列  每次查询区间的max-min是多少 思路:直接维护max 和min即可  写两个query分别查最大最小值 #include<cstdio> #include<algorithm> #include<set> #include<vector> #include<cstring> #include<iostream> using namespace std; ; int a[maxn]; struct Node{…
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 organize a game of Ultimate Frisbee with some of the cows. To keep things simple, he will take a contiguous range of cows fr…
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define MAXN 50010 int n , q; int h[MAXN]; struct Node{ int l; int r; int minNum; int maxNum; } tr[*MAXN]; void build(int l,int r,int u)…
依然延续第一篇读书笔记,这一篇是基于<ACM/ICPC 算法训练教程>上关于线段树的讲解的总结和修改(这本书在线段树这里Error非常多),但是总体来说这本书关于具体算法的讲解和案例都是不错的. 线段树简介 这是一种二叉搜索树,类似于区间树,是一种描述线段的树形数据结构,也是ACMer必学的一种数据结构,主要用于查询对一段数据的处理和存储查询,对时间度的优化也是较为明显的,优化后的时间复杂为O(logN).此外,线段树还可以拓展为点树,ZWK线段树等等,与此类似的还有树状数组等等. 例如:要将…
题目传送门 /* 题意:输入 1 a:询问是不是有连续长度为a的空房间,有的话住进最左边 输入 2 a b:将[a,a+b-1]的房间清空 线段树(区间合并):lsum[]统计从左端点起最长连续空房间数,rsum[]类似,sum[]统计区间最长连续的空房间数, 它有三种情况:1.纯粹是左端点起的房间数:2.纯粹是右端点的房间数:3.当从左(右)房间起都连续时,加上另一个子节点 从左(右)房间起的数,sum[]再求最大值更新维护.理解没错,表达能力不足 详细解释:http://www.cnblog…
n个人 他要插入的位置 和权值(这东西就最后输出来的) 倒的插就一定是他自己的位子 一个线段树维护一下就可以了 nlog(n) #include<stdio.h> #include<algorithm> using namespace std; #define MAXN 200010 int z[MAXN],w[MAXN],ans[MAXN]; struct node { int l,r,si; }x[MAXN<<]; void Build(int l,int r,in…
题目传送门 题意:四种集合的操作,对应区间的01,问最后存在集合存在的区间. 分析:U T [l, r]填充1; I T [0, l), (r, N]填充0; D T [l, r]填充0; C T[0, l), (r, N]填充0并且[l, r]xor; S T [l, r]xor 线段树结点两个属性,cover[o]: 该区间是否填充(1, 0, -1),_xor[o]: 该区间是否异或反转(1, 0).最后(和[的区别可以原数*2判奇偶得 #include <cstdio> #includ…
这题,看到别人的解题报告做出来的,分析: 大概意思就是: 数组sum[i][j]表示从第1到第i头cow属性j的出现次数. 所以题目要求等价为: 求满足 sum[i][0]-sum[j][0]=sum[i][1]-sum[j][1]=.....=sum[i][k-1]-sum[j][k-1] (j<i) 中最大的i-j 将上式变换可得到 sum[i][1]-sum[i][0] = sum[j][1]-sum[j][0] sum[i][2]-sum[i][0] = sum[j][2]-sum[j]…
Description Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been able to narrow down the list of features shared by his cows to a list of only K different features (1 ≤ K ≤ 30). For example, cows exhibiting feature #1…
题目传送门 #include <cstdio> #include <cstring> #define lson l, m, rt << 1 #define rson m+1, r, rt << 1 | 1 + ; ]; struct node { ]; int val; }boy[MAX_N<<]; int ans[MAX_N]; int id; int n, k; void build(int l, int r, int rt) { sum[r…
题目传送门 /* 结点存储下面有几个空位 每次从根结点往下找找到该插入的位置, 同时更新每个节点的值 */ #include <cstdio> #define lson l, m, rt << 1 #define rson m+1, r, rt << 1 | 1 + ; int pos[MAX_N], val[MAX_N]; ]; int que[MAX_N]; int id; void build(int l, int r, int rt) { sum[rt] = r…
/******************************************************* 题目: Balanced Lineup(poj 3264) 链接: http://poj.org/problem?id=3264 题意: 给个数列,查询一段区间的最大值与最小值的差 算法: RMQ ********************************************************/ #include<cstdio> #include<cstrin…
点我看题目 题意 :N头奶牛,Q次询问,然后给你每一头奶牛的身高,每一次询问都给你两个数,x y,代表着从x位置上的奶牛到y位置上的奶牛身高最高的和最矮的相差多少. 思路 : 刚好符合RMQ的那个求区间最大最小值,所以用RMQ还是很方便的.就是一个RMQ的模板题,基本上书上网上都有. RMQ基础知识 RMQ算法举例 #include <stdio.h> #include <string.h> #include <math.h> #include <iostream…
G - Balanced Lineup POJ - 3264 思路:水题,线段树的基本操作即可. #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define MAXN 50010 using namespace std; int n,q; struct nond{ int l,r,min,max; }tree[MAXN*]; void up(int now…
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…
Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 68466   Accepted: 31752 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: 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: 34306   Accepted: 16137 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: 34140   Accepted: 16044 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…
题目链接: http://poj.org/problem?id=3264 思路分析: 典型的区间统计问题,要求求出某段区间中的极值,可以使用线段树求解. 在线段树结点中存储区间中的最小值与最大值:查询时使用线段树的查询 方法并稍加修改即可进行查询区间中最大与最小值的功能. 代码(线段树解法): #include <limits> #include <cstdio> #include <iostream> using namespace std; ; + ; struct…
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…
[题目链接] http://poj.org/problem?id=3264 [题目大意] 求区间最大值和最小值的差值 [题解] 线段树维护区间极值即可 [代码] #include <cstdio> #include <algorithm> #include <cstring> #include <climits> using namespace std; const int N=1000010; int T[N*4],C[N*4],n,M,m; struct…
http://poj.org/problem?id=3264 题目大意: 给定N个数,还有Q个询问,求每个询问中给定的区间[a,b]中最大值和最小值之差. 思路: 依旧是线段树水题~ #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int MAXN=50000+10; const int MAXM=MAXN<<2; const int INF=…
  Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 75294   Accepted: 34483 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 J…
一段区间的最值问题,用线段树或RMQ皆可.两种代码都贴上:又是空间换时间.. RMQ 解法:(8168KB 1625ms) #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <cstdlib> using namespace std; #define N 50003 ],dmax…
Balanced Lineup 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 organize a game of Ultimate Frisbee with some of the cows. To keep things simple, he will take a…
<题目链接> 题目大意: 求给定区间内最大值与最小值之差. 解题分析: 线段树水题,每个节点维护两个值,分别代表该区间的最大和最小值即可. #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 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 organize a game of Ultimate Frisbee with some of the cows. To keep things simple, he will take a contiguous…