「NOIP2016」蚯蚓

传送门
Luogu

解题思路

很容易想到用一个堆去维护,但是复杂度是 \(O((n+m)\log(n+m))\) 的,显然过不了 \(7e6\)
其实这题有一个性质:
先被切开的蚯蚓,得到的两条新蚯蚓,一定会比后被切开的蚯蚓长。
这个可以推一下表达式,我就不打了。
那么也就是说,我们需要维护三个队列,其中每个队列的元素都是具有单调性的。
代码细节有点小多。

细节注意事项

  • 咕咕咕

参考代码

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
    s = 0; int f = 0; char c = getchar();
    while (!isdigit(c)) f |= (c == '-'), c = getchar();
    while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
    s = f ? -s : s;
}
int n, m, qq, u, v, t, a[100010];
int hd[3], tl[3], q[3][7000010];
inline int Max() {
    int _max = -2147483648, p;
    for (rg int i = 0; i < 3; ++i)
        if (hd[i] < tl[i] && q[i][hd[i] + 1] > _max)
            _max = q[i][hd[i] + 1], p = i;
    return ++hd[p], _max;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
#endif
    read(n), read(m), read(qq), read(u), read(v), read(t);
    for (rg int i = 1; i <= n; ++i) read(q[0][++tl[0]]);
    sort(q[0] + 1, q[0] + tl[0] + 1, greater < int > ());
    int delta = 0;
    for (rg int i = 1; i <= m; ++i) {
        int x = Max() + delta;
        if (i % t == 0)
            printf("%d%c", x, " \n"[i + t > m]);
        int ls = 1ll * x * u / v, rs = x - ls;
        delta += qq;
        q[1][++tl[1]] = ls - delta;
        q[2][++tl[2]] = rs - delta;
    }
    if (t > m) puts("");
    for (rg int i = 1; i <= n + m; ++i) {
        int x = Max() + delta;
        if (i % t == 0)
            printf("%d%c", x, " \n"[i + t > n + m]);
    }
    return 0;
}

完结撒花 \(qwq\)

猜你喜欢

转载自www.cnblogs.com/zsbzsb/p/11745899.html