求助 TG T2 (码风良好)

线段树TLE,只有30分

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int MAXN = 1e6+5;
int N, M;
long long K, D;

struct Node {
    int l, r;
    long long lmx, rmx, mx, sum;
} tr[MAXN * 4];

void pushup(int k) {
    int lc = k << 1;
    int rc = lc | 1;
    tr[k].lmx = max(tr[lc].lmx, tr[rc].lmx + tr[lc].sum);
    tr[k].rmx = max(tr[rc].rmx, tr[lc].rmx + tr[rc].sum);
    tr[k].sum = tr[lc].sum + tr[rc].sum;
    tr[k].mx = max({tr[lc].mx, tr[rc].mx, tr[lc].rmx + tr[rc].lmx});
}

void build(int k, int l, int r) {
    tr[k] = {l, r, 0, 0, -K, -K};
    if (l == r) return;
    int md = l + r >> 1;
    build(k << 1, l, md);
    build(k << 1 | 1, md + 1, r);
}

void update(int k, int x, long long y) {
    if (tr[k].l == tr[k].r) {
        tr[k].sum += y;
        tr[k].mx = tr[k].sum;
        tr[k].lmx = tr[k].rmx = max(0ll, tr[k].sum);
        return;
    }
    int md = tr[k].l + tr[k].r >> 1;
    if (x <= md) update(k << 1, x, y);
    else update(k << 1 | 1, x, y);
    pushup(k);
}

signed main() {
    // freopen ("B.in", "r", stdin);
    // freopen ("B.out", "w", stdout);
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> M >> K >> D;
    build(1, 1, N);
    for (int i = 1; i <= M; i++) {
        int x, y;
        cin >> x >> y;
        update(1, x, y);
    // cerr << "OK" << endl;
        if (tr[1].mx > K * D) cout << "NO" << endl;
        else cout << "YES" << endl;
    }

    return 0;
}

全部评论

相关推荐

鼗:四级有点难绷,感觉能拿国家励志奖学金,学习能力应该蛮强的,四级确实不重要,但是拿这个卡你可是很恶心啊
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务