数据加强了,原来nlogn的复杂度就不行了...... 首先对原来的n个数排序(注意不能用快排),因为值域是1e5,所以可以开桶排序,开两个队列,一个存原来的n个数(已经满足单增),另一队列存两两合并后的数(也是满足单调性的),每次合并从两个队列中选取最小的两个数,合并后放入第二个队列就行了. 更难的题目还是蚯蚓,其中隐晦的单调性与此类似. 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define int long long 4 qu…
P2912 [USACO08OCT]牧场散步Pasture Walking 题目描述 The N cows (2 <= N <= 1,000) conveniently numbered 1..N are grazing among the N pastures also conveniently numbered 1..N. Most conveniently of all, cow i is grazing in pasture i. Some pairs of pastures are…