POJ 3145 线段树 分块?+暴力】的更多相关文章

思路: 线段树 (分类讨论) 此题数据很水 数据很水 数据很水 但是卡个暴力还是没问题的-- //By SiriusRen #include <cstdio> #include <cstring> using namespace std; #define maxn 1500000 #define inf 1061109567 int n,tot,jy,xx,yy,tree[maxn*6],vis[maxn],cases,q[maxn]; inline int min(int x,i…
题面传送门 首先注意到这次行数与列数不同阶,列数只有 \(200\),而行数高达 \(5000\),因此可以考虑以行为下标建线段树,线段树上每个区间 \([l,r]\) 开一个 \(200\times 200\) 的数组 \(d_{i,j}\) 表示从 \((l,i)\) 到 \((r,j)\) 的最短路,合并暴力用类似 floyd 的方式进行转移,这样暴力时间复杂度是 \(RC^3+mC^2\log R+q\),空间复杂度 \(RC^2\),其中 \(m\) 为修改次数,一脸无法通过,而且 T…
Who Gets the Most Candies? Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 12744   Accepted: 3968 Case Time Limit: 2000MS Description N children are sitting in a circle to play a game. The children are numbered from 1 to N in clockwise…
题解: 考虑用线段树维护楼的最大值,然后这个问题就很简单了. 每次可以向左二分出比x高的第一个楼a,同理也可以向右二分出另一个楼b,如果a,b都存在,答案就是b-a-1. 注意到二分是可以直接在线段树上进行的,所以复杂度是O(nlogn). 当然这里是用分块做的,更暴力一些. #include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace st…
题意 http://www.ioi2013.org/wp-content/uploads/tasks/day1/wombats/Wombats%20zh%20(CHN).pdf 思路 ​ 我们设矩形的行数为 \(n(5000)\) ,列数为 \(m(200)\) ,更新次数为 \(U(500)\) ,查询次数为 \(Q(2\times 10^5)\) . ​ 最暴力的思想是一次更新处理出从一个 \(m^2\) 的数组,代表第一行的每一个点走到最后一行每一个点的最小代价,然后 \({\cal O}…
Description 有一个长度为n的数组{a1,a2,...,an}.m次询问,每次询问一个区间内最小没有出现过的自然数. Input 第一行n,m. 第二行为n个数. 从第三行开始,每行一个询问l,r. Output 一行一个数,表示每个询问的答案. Sample Input 5 5 2 1 0 2 1 3 3 2 3 2 4 1 2 3 5 Sample Output 1 2 3 0 3 HINT 数据规模和约定 对于100%的数据: 1<=n,m<=200000 0<=ai&l…
http://poj.org/problem?id=3468 题意:给n个数字,从A1 …………An m次命令,Q是查询,查询a到b的区间和,c是更新,从a到b每个值都增加x.思路:这是一个很明显的线段树的题目,就是线段树的用区间更新就可以,我也是第一次用.. #include <stdio.h> #include <string.h> #define maxn 100050 long long arra[ maxn ]; struct note{ //要用long long 类型…
题目: 输入两个数(m,n),m表示牛的头数,n表示查询的个数.查询时输入两个数(x,y),表示查询范围的起始值和终止值,查询结果是,这个区间内牛重量的最大值减去牛重量的最小值,数量级为1000,000 设计每次查询的复杂度为logm. 例如, 输入: 6 3 1 7 3 4 2 5 1 5 4 6 2 2 输出: 6 3 0     分析:这道题是典型的空间换时间的题.一看到是区间的查找,我们应该想到线段树,这里有一篇我觉得写得挺好的介绍线段树的博客和大家分享一下:http://www.cnb…
Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 15422   Accepted: 7684 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue… The Lunar New Year wa…
我原来准备做方差的.. 结果发现不会维护两个标记.. 就是操作变成一个 a*x+b ,每次维护a , b 即可 加的时候a=1 ,b=v 乘的时候a=v ,b=0 #include <cstdio> ; long long a[Maxn],n,P,l,r,c,m,type; struct Node { long long mul,add,sum,len; }tree[Maxn<<]; inline void Change(long long o,long long mul,long…