Codeforces Global Round 5 D. Balanced Playlist

D. Balanced Playlist

https://codeforces.com/contest/1237/problem/D
Every morning, you choose a track. The playlist then starts playing from this track in its usual cyclic fashion. At any moment, you remember the maximum coolness x of already played tracks. Once you hear that a track with coolness strictly less than x2 (no rounding) starts playing, you turn off the music immediately to keep yourself in a good mood.
他要听歌 从i开始 到 j 结束 这个区间的最大值/2 < a[j] 这个值 他就可以听这个歌
我们慢慢就可以想到 j这个位置 是单调往后的 没有必要每次都找
比如 5 2 9 18 24 2
我们 5开始 他到2 就停了 但是 2开始 可以一直到24
之后每个数据 除了 最后一个 都可以到 24
所以这题就变成维护一个最远端了
i一直往后 到 j 最大值/2 < a[j] 就可以放入 j

#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int INF = 0x3f3f3f3f;
int n, m;

int tree[maxn << 2];
int a[maxn];

inline void push_up(int rt) {
    tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]);
}

void build(int l, int r, int rt) {
    if(l == r) {
        tree[rt] = a[l];
        return ;
    }
    int mid = l + r >> 1;
    if(l <= mid)
        build(l, mid, rt << 1);
    if(r > mid)
        build(mid + 1, r, rt << 1 | 1);
    push_up(rt);
}

int quemax(int L, int R, int l, int r, int rt) {
    if(L <= l && R >= r)
        return tree[rt];
    int mid = l + r >> 1;
    int res = -1;
    if(L <= mid)
        res = max(res, quemax(L, R, l, mid, rt << 1));
    if(R > mid)
        res = max(res, quemax(L, R, mid + 1, r, rt << 1 | 1));
    return res;
}

signed main() {
    cin >> n;
    for(int i = 1; i <= n; i ++) cin >> a[i];
    for(int i = n + 1; i <= 2 * n; i ++) a[i] = a[i - n];
    for(int i = 2 * n + 1; i <= 3 * n; i ++) a[i] = a[i - n];
    n *= 3;
    build(1, n, 1);
    int j = 2;
    for(int i = 1; i <= n/3; i ++) {
        for(; j <= 3 * n; j ++) {
            if(quemax(i, j, 1, n, 1) > a[j] * 2) break;
        }
        if(j - i > n/3*2) cout << -1 << " ";
        else cout << j - i << " ";
    }
    return 0;
}

全部评论

相关推荐

今天周一休息,突发奇想写一篇阶段总结。如题,我已经去了一个和Java彻底毫无关联的行业。曾经我以为自己能在计算机行业发光发热,没想到刚入行一年多就当了逃兵。从最开始的热爱到现在一看到代码就厌恶,不知道自己经历了什么。所以我去干什么了?答案是:在成都当了租房销售。上班那会压力大了就念叨着去干租房中介,但是一直下不去这个决心,想着自己学了四年多的计算机知识,终究还是不甘心。终于在某一天准备八股文的时候,看着无数篇和工作内容关系不大的理论知识,那一刻下定决心,决定尝试一下销售行业,也算是给自己一个交代。后面阴差阳错的投了成都自如去当租房管家,没想到面试很顺利,在当天一百多个面试的人里面,我成为了为数不多通过的几个幸运儿之一。目前已经培训通过,正式入职,也开了单,也有压力但是每天过得很开心,真心喜欢那种和人交流的感觉,哪怕是最后没有选择找我租房。说这些也是想告诉那些大三,大四正在找Java实习而焦虑的同学:你们现在还年轻,选择很多,容错率也很高,可以尽情去尝试自己喜欢的行业和工作。不用因为某一次的面试没通过或者简历石沉大海而焦虑,更不用因为身边人都在挤编程的独木桥就强迫自己跟风。也算是自己的碎碎念吧,也希望自己能在新的领域取得一点小成就。也祝牛油工作顺利!
沉淀小子:干啥都不丢人啊,生存是必须要的,销售很考验一个人综合素质能力的,好的销售人脉和资源可不比写字楼的白领差啊
点赞 评论 收藏
分享
程序员小白条:可以,技术栈别写太多,因为学院本这块,没必要太多,项目的话可以提前,技术栈放最下面,要么技术栈放最前面,多准备下八股文
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务