Lpl and Energy-saving Lamps - 计蒜客

Posted zgglj-com

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Lpl and Energy-saving Lamps - 计蒜客相关的知识,希望对你有一定的参考价值。

技术分享图片

const int N = 100005;

int n, m, q, flag, cnt;
int Min[4 * N], d[N];

void Pushup(int root) {
    Min[root] = min(Min[lson], Min[rson]);
}

void Build(int l, int r, int root) {
    if (l == r) {
        sc(Min[root]);
        return;
    }
    int mid = (l + r) >> 1;
    Build(l, mid, lson);
    Build(mid + 1, r, rson);
    Pushup(root);
}

void Update(int l, int r, int root, int x) {
    if (Min[root] > x) return;
    if (l == r) {
        flag = Min[root];
        Min[root] = INF32;
        cnt++;
        return;
    }
    int mid = (l + r) >> 1;
    if (Min[lson] > x) Update(mid + 1, r, rson, x);
    if (Min[lson] <= x) Update(l, mid, lson, x);
    Pushup(root);
}

P ans[N];

int main()
{
    sc(n), sc(m);
    Build(1, n, 1);
    sc(q);
    Rep(i, 1, q) sc(d[i]);

    int tp = 0;
    Rep(i, 1, q) {
        if (Min[1] == INF32) {
            ans[i].first = cnt;
            ans[i].second = tp;
            continue;
        }
        tp += m;
        while(1) {
            flag = 0;
            Update(1, n, 1, tp);
            if (!flag) break;
            tp -= flag;
        }

        ans[i].first = cnt;
        ans[i].second = tp;
    }

    Rep(i, 1, q) printf("%d %d
", ans[d[i]].first, ans[d[i]].second);
    return 0;
}

 

以上是关于Lpl and Energy-saving Lamps - 计蒜客的主要内容,如果未能解决你的问题,请参考以下文章

计蒜客 Lpl and Energy-saving Lamps(二分+线段树区间最小)

[ACM][2018南京预赛]Lpl and Energy-saving Lamps

ACM-ICPC 2018 南京赛区网络预赛 Lpl and Energy-saving Lamps 线段树

线段树求区间第一个不大于val的值Lpl and Energy-saving Lamps

ACM-ICPC 2018 南京赛区网络预赛 G Lpl and Energy-saving Lamps(线段树)

ACM-ICPC 2018 南京赛区网络预赛 G. Lpl and Energy-saving Lamps (弱线段树)