http://poj.org/problem?id=3277 City Horizon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15255 Accepted: 4111 Description Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and o…
http://poj.org/problem?id=3667 Hotel Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9484 Accepted: 4066 Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny s…
Cows 题目:http://poj.org/problem?id=2481 题意:有N头牛,每仅仅牛有一个值[S,E],假设对于牛i和牛j来说,它们的值满足以下的条件则证明牛i比牛j强壮:Si <=Sjand Ej <= Ei and Ei - Si > Ej - Sj. 如今已知每一头牛的測验值,要求输出每头牛有几头牛比其强壮. 思路:将牛依照S从小到大排序.S同样依照E从大到小排序,这就保证了排在后面的牛一定不比前面的牛强壮. 再依照E值(离散化后)建立一颗线段树(这里最值仅仅有1…
poj 3225 这题是用线段树解决区间问题,看了两天多,算是理解一点了. Description LogLoader, Inc. is a company specialized in providing products for analyzing logs. While Ikki is working on graduation design, he is also engaged in an internship at LogLoader. Among his tasks, one is…
此题为入门级线段树 题意:给定Q(1<=Q<=200000)个数A1A2…AQ,多次求任一区间Ai-Aj中最大数和最小数的差 #include<algorithm> #include<cstdio> #include<string> #include<string.h> #include<iostream> using namespace std; typedef long long LL; const int INF = 0x7FF…
给出一个n个元素的序列,序列有正数也有负数 支持3个操作: p x y 0.p=0时,把第x个的值改为y 1.p=1时,交换第x个和第y个的值 2.p=2时,问区间[x,y]里面连续k个的子序列的最大和(保证y-x+1>=k) 我们只要定义数组v v[i]表示原序列中,从第i个开始,连续k个元素的值的和 然后我们只需要维护一棵线段树,树的叶子节点表示数组v 树的节点维护: 区间[l,r]中,连续k个的子序列的最大和,即数组v的最大值 这样的话,3个操作就变为: 0.把区间[max(x-k+1,0…
Stars Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given st…
按顺时针给出n个小孩,n个小孩每个人都有一个纸,然后每个人都有一个val,这个val等于自己的因子数,如果这个val是正的,那就顺时针的第val个孩子出去,如果是负的话,就逆时针的第val个孩子出去,所以可以用线段树维护一个区间内的孩子数,然后找到下一个孩子是这些人里的第k个人,用线段树找到剩下的第k个人的位置,然后把这个地方更新成0,这样模拟过程. 反素数:反素数就是从区间1 - i 内的数的因子数都比 i 的因子数少的数,这题中因为同样的val值时选择出队早的人,其实就是1-n内的最大反素数…
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 51098 Accepted: 14788 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral post…
F - Permutation 思路:对于当前的值x, 只需要知道x + k, x - k这两个值是否出现在其左右两侧,又因为每个值只有一个, 所以可以转换成,x+k, x-k在到x所在位置的时候是否都出现,或者都不出现,即出现情况相等,我们可以 用线段树维护hash值的方式来判断所有x+k, x-k的出现情况是否都一样. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #defi…