USACO08FEB Hotel】的更多相关文章

题目传送门 线段树维护区间 线段树结构体 struct zzz{ int l,r,mi; //l为以左端点的为起点的最长子串 //r为以右端点为终点的最长子串 //mi是区间内部的最长子串 }tree[50010<<2]; 合并 合并的时候要考虑左右区间互拼的情况 inline void up(int l,int r,int p){ if(tree[ls].l==mid-l+1) tree[p].l=tree[ls].l+tree[rs].l; else tree[p].l=tree[ls].…
正确的题解 首先我们都知道这题要用线段树做.考虑维护靠左边的answer,靠右边的answer,和整个区间的answer,那么就珂以维护这道题目了. 这里比较复杂的有下传操作和上传操作. 上传 void pushUp(int pos, int l, int r){ seg[pos].ans = max(seg[pos << 1].rans + seg[pos << 1 | 1].lans, max(seg[pos << 1].ans, seg[pos <<…
P2894 [USACO08FEB]酒店Hotel https://www.luogu.org/problem/show?pid=2894 题目描述 The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever the competent travel…
题面:P2894 [USACO08FEB]酒店Hotel 题解:和基础的线段树操作差别不是很大,就是在传统的线段树基础上多维护一段区间最长的合法前驱(h_),最长合法后驱(t_),一段中最长的合法区间(mx).询问时由于查询的是最左边的合法端点,所以要从左到中间到右边依次考虑情况. 代码: #include<cstdio> #include<cstring> #include<iostream> #define max(a,b) ((a)>(b)?(a):(b))…
P2894 [USACO08FEB]酒店Hotel 简单的线段树维护区间信息. 维护三个值,一个是从左端点能拓展的长度,一个是从右端点能脱产的的长度.另一个是整个区间内的最大连续零一长度. 记录这三个值的目的在于可以使小区间合并大区间. 这样话就可以愉快的跑出答案了. #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> using std::max; using…
P2894 [USACO08FEB]酒店Hotel 题目描述 The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever the competent travel agent, has named the Bullmoose Hotel on fam…
P2894 [USACO08FEB]酒店Hotel 参考样例,第一行输入n,m ,n代表有n个房间,编号为1---n,开始都为空房,m表示以下有m行操作,以下 每行先输入一个数 i ,表示一种操作: 若i为1,表示查询房间,再输入一个数x,表示在1--n 房间中找到长度为x的连续空房,输出连续x个房间中左端的房间号,尽量让这个房间号最小,若找不到长度为x的连续空房,输出0. 若i为2,表示退房,再输入两个数 x,y 代表 房间号 x---x+y-1 退房,即让房间为空. 题目描述有坑啊... 一…
今天我们说说线段树. 我个人还是非常欣赏这种数据结构的.(逃)因为它足够优美,有递归结构,有左子树和右子树,还有二分的思想. emm这个文章打算自用,就不写那些基本的操作了... 1° 简单的懒标记(仅含加法) 当我们进行区间修改(比如同时加上一个数)时,我们现在也许暂时不用它,可以当需要用的时候再改.这个时候我们就需要做个标记,这个标记就是懒标记,$lazy$.如果在后续的指令中需要从p向下递归,我们这时候检查它是否有标记.若有,就按照标记更新两个子节点,同时为子节点增加标记,清除p的标记.…
[USACO08FEB]酒店Hotel 线段树 题面 其实就是区间多维护一个lmax,rmax(表示从左开始有连续lmax个空房,一直有连续rmax个空房到最右边),合并时讨论一下即可. void push_up(int x, int l, int r){ int mid=(l+r)>>1; if(sum[lson]==mid-l+1) lmax[x]=sum[lson]+lmax[rson]; else lmax[x]=lmax[lson]; if(sum[rson]==r-(mid+1)+…
题目传送门 酒店 题目描述 The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever the competent travel agent, has named the Bullmoose Hotel on famed Cumberland Str…
题目描述 The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever the competent travel agent, has named the Bullmoose Hotel on famed Cumberland Street as th…
题目描述 The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever the competent travel agent, has named the Bullmoose Hotel on famed Cumberland Street as th…
题目描述 The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever the competent travel agent, has named the Bullmoose Hotel on famed Cumberland Street as th…
题目大意 多次操作 查询并修改区间内长度==len的第一次出现位置 修改区间,变为空 思路 类似于求区间最大子段和(应该是这个吧,反正我没做过) 维护区间rt的 从l开始向右的最长长度 从r开始向左的最长长度 l到r内的最长长度 反正维护的是个01序列, 随便做 又是小错误,第一遍就能过非得debug一小时 这里懒惰标记有两个,开bool为了省 省不了多少的 内存gg了(可以过样例也是神奇,也许是windows吧) 还有样例好坑啊,我以为是\([5,10]\)(其实是我没认真看) 代码 #inc…
问题描述 奶牛们最近的旅游计划,是到苏必利尔湖畔,享受那里的湖光山色,以及明媚的阳光.作为整个旅游的策划者和负责人,贝茜选择在湖边的一家著名的旅馆住宿.这个巨大的旅馆一共有N (1 <= N <= 50,000)间客房,它们在同一层楼中顺次一字排开,在任何一个房间里,只需要拉开窗帘,就能见到波光粼粼的湖面. 贝茜一行,以及其他慕名而来的旅游者,都是一批批地来到旅馆的服务台,希望能订到D_i (1 <= D_i <= N)间连续的房间.服务台的接待工作也很简单:如果存在r满足编号为r…
比较基础的线段树了 我们要维护最大连续子串,这个可以说是一个比较套路的操作了 我们在[SHOI2009]会场预约这道题中已经比较深刻的认识到了这个套路了 对于这道题,我们显然要知道一个区间内最大的全为1(我的代码里用1表示空房)子串长度是多少,那怎么办呢 我们多开几个数组 \(d[i]\)表示\(i\)这个区间内最大的全为1子串长度 \(rc[i]\)表示\(i\)这个区间内从左端开始的最大全为1子串长度 \(lc[i]\)表示\(i\)这个区间内从右端开始的最大全为1子串长度 于是我们做pus…
嘟嘟嘟 这道题以前在学校内网刷过类似的,AC了后还挺有成就感,所以更详细的题解请看这里. 总的来说,就是用线段树维护区间最长连续0.因此我们要维护这么几个值:lmax:从当前区间左端点开始最长的连续0的长度:rmax:右端点开始最长连续0的长度:imax当前区间最长连续0的长度.有了这三个量,区间就可以合并了. 合并的方法看上面的链接,这里不再细讲了,这道题主要的区别查询. 查询是找长度为x的区间的位置,而不是在给定区间中查询最长连续区间.查询的具体步骤是这样的: 1.当前区间连续的最长长度比要…
Descripion 奶牛们最近的旅游计划,是到苏必利尔湖畔,享受那里的湖光山色,以及明媚的阳光.作为整个旅游的策划者和负责人,贝茜选择在湖边的一家著名的旅馆住宿.这个巨大的旅馆一共有N (1 <= N <= 50,000)间客房,它们在同一层楼中顺次一字排开,在任何一个房间里,只需要拉开窗帘,就能见到波光粼粼的湖面. 贝茜一行,以及其他慕名而来的旅游者,都是一批批地来到旅馆的服务台,希望能订到D_i (1 <= D_i <= N)间连续的房间.服务台的接待工作也很简单:如果存在r…
跟线段树求区间最值一样每个节点维护左边开始的最大连续空房间数.右边开始的最大连续空房间数.这个区间内的最大连续空房间数 #include <iostream> #include <cstdio> using namespace std; int n, m, opt, uu, vv; struct SGT{ int lma[200005], rma[200005], sum[200005], tag[200005]; //sum means there are how many em…
https://www.luogu.org/problem/P2894 #include<cstdio> #include<iostream> using namespace std; struct ben { int lmax,rmax,len,sum,lz; }tr[400005]; void bt(int x,int l,int r)//建树 { tr[x].lz=0;//标记清空 tr[x].sum=tr[x].len=tr[x].lmax=tr[x].rmax=r-l+1…
P2894 [USACO08FEB]酒店Hotel 题目描述 The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever the competent travel agent, has named the Bullmoose Hotel on fam…
Hotel 转载自:http://www.cnblogs.com/scau20110726/archive/2013/05/07/3065418.html [题目链接]Hotel [题目类型]线段树 区间合并 &题意: 有一个线段,从1到n,下面m个操作,操作分两个类型,以1开头的是查询操作,以2开头的是更新操作 1 w 表示在总区间内查询一个长度为w的可用区间,并且要最靠左,能找到的话返回这个区间的左端点并占用了这个区间,找不到返回0 好像n=10 , 1 3 查到的最左的长度为3的可用区间就…
Hotel Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever th…
Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever the competent travel agent, has named the Bullmoose Hotel on famed Cumberland Stree…
Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever the competent travel agent, has named the Bullmoose Hotel on famed Cumberland Stree…
Holiday Hotel   Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8302   Accepted: 3249 Description Mr. and Mrs. Smith are going to the seaside for their holiday. Before they start off, they need to choose a hotel. They got a list of hotel…
数据库字段和类Object属性不匹配,Method threw 'org.hibernate.exception.SQLGrammarException' exception. Cannot evaluate com.hotel.Object_$$_jvst485_15.toString()…
Hotel Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 10858Accepted: 4691 Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever…
题目链接:http://poj.org/problem?id=3667 题意:有一个hotel有n间房子,现在有2种操作: 1 a,check in,表示入住.需要a间连续的房子.返回尽量靠左的房间编号并更新. 2 a b,check out,从a开始退房,一共退到a+b-1. seg数组l表示从左边开始数空房子的个数,r表示从右边数空房子的个数,s表示一共最多是有s个连续的空房子. add作为延迟标记有3种状态:-1表示不操作,0表示退房,1表示入住. pushUP:向上更新,需要更新seg[…
暴力/树形DP 要求在树上找出等距三点,求方案数,那么用类似Free Tour2那样的合并方法,可以写出: f[i][j]表示以 i 为根的子树中,距离 i 为 j 的点有多少个: g[i][j]表示以 i 为根的子树中,选出两点,剩下那点距离 i 为 j 的方案数: 那么就可以在搜索完一棵子树的时候用g[i]和f[to[i]]更新答案,然后更新f[i]和g[i],最后还要考虑g[i]和祖先的配对情况…… 但是我写跪了= =后来一看题解……$N\leq 5000$!!!直接$N^2$暴力啊,搞什…