线段树.. -------------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream>   #define rep( i , n ) for( int i = 0 ; i < n ; i++ ) #define…
题目 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 553  Solved: 307[Submit][Status] Description Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some preci…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1651 题意: 给你n个线段[a,b],问你这些线段重叠最多的地方有几层. 题解: 先将线段按左端点a升序排序. 开一个优先队列q(升序排序),里面存线段的右端点b. 枚举线段i,然后: (1)将q中所有小于a[i]的元素弹出. (2)插入b[i]. (3)更新ans = max(ans,q.size()) AC Code: #include <iostream> #include &l…
这个题方法还挺多的,不过洛谷上要输出方案所以用堆最方便 先按起始时间从小到大排序. 我用的是greater重定义优先队列(小根堆).用pair存牛棚用完时间(first)和牛棚编号(second),每次查看队首的first是否比当前牛的起始时间早,是则弹出队首记录当前牛的答案,再把新的pair放进去,否则增加牛棚,同样要塞进队里 #include<iostream> #include<cstdio> #include<algorithm> #include<que…
1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 566  Solved: 314[Submit][Status] Description Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some precise…
http://www.lydsy.com/JudgeOnline/problem.php?id=1651 很奇妙.. 我们发现,每一时刻的重叠数选最大的就是答案.... orz 那么我们可以线段树维护每个点的次数... 然后就ok了.. 第二种做法:用前缀和来维护即可... 线段树: #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <ios…
1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 509  Solved: 280[Submit][Status] Description Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some precise…
BZOJ 洛谷 \(dsu\ on\ tree\).(线段树合并的做法也挺显然不写了) 如果没写过\(dsu\)可以看这里. 对修改操作做一下差分放到对应点上,就成了求每个点子树内出现次数最多的颜色,这就和CF600E类似了.直接用\(dsu\). 修改某个颜色出现次数的时候,最大值不能\(O(1)\)求出,得套个\(set\),所以复杂度是\(O(q\log^2n)\).但常数并不大. 关于复杂度,在CF600E中对一个点的修改是\(O(1)\)的,而本题中可能是\(O(q)\)(一个点上挂着…
dp( L , R ) = max( dp( L + 1 , R ) + V_L * ( n - R + L ) , dp( L , R - 1 ) + V_R * ( n - R + L ) ) 边界 : dp( i , i ) = V[ i ] * n -------------------------------------------------------------------------------------------- #include<cstdio> #include&l…
题目 1652: [Usaco2006 Feb]Treats for the Cows Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 234  Solved: 185[Submit][Status] Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ se…