求hack
查看原帖
求hack
1211195
wangpinyi楼主2024/9/16 17:59

感觉时间复杂度不太对,但是造不出来hack数据

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

#define N 200010
#define M 800010
#define int long long

int n,q;
struct MOVE {
    int x,d,l;
} moves[N];

struct Node {
    int xays; // min (x + y)
    int xayd; // max (x + y)
    int xmys; // min (x - y)
    int xmyd; // max (x - y)
    int lazy1; // D = 1的懒标记
    int lazy2; // D = 2的懒标记
    int nowx; // 仅仅是为了根节点
} t[M];

void pushup(int x) { // 偷懒函数(什)
    t[x].xays = min(t[x << 1].xays,t[(x << 1) | 1].xays);
    t[x].xayd = max(t[x << 1].xayd,t[(x << 1) | 1].xayd);
    t[x].xmys = min(t[x << 1].xmys,t[(x << 1) | 1].xmys);
    t[x].xmyd = max(t[x << 1].xmyd,t[(x << 1) | 1].xmyd);
}

void build(int l,int r,int x) {
    if(l == r) {
        // 根节点
        t[x].nowx = l;
        t[x].xays = l;
        t[x].xayd = l;
        t[x].xmys = l;
        t[x].xmyd = l;
        return;
    }
    int mid = (l + r) >> 1;
    build(l,mid,(x << 1));
    build(mid + 1,r,((x << 1) | 1));
    pushup(x);
}
void pushdown(int x){
    if(t[x].lazy2) {
        t[x << 1].lazy2 += t[x].lazy2;
        t[x << 1].xmyd += 2 * t[x].lazy2;
        t[x << 1].xmys += 2 * t[x].lazy2;

        t[(x << 1) | 1].lazy2 += t[x].lazy2;
        t[(x << 1) | 1].xmyd += 2 * t[x].lazy2;
        t[(x << 1) | 1].xmys += 2 * t[x].lazy2;

        t[x].lazy2 = 0;
    }

    if(t[x].lazy1) {
        t[x << 1].lazy1 += t[x].lazy1;
        t[x << 1].xayd -= 2 * t[x].lazy1;
        t[x << 1].xays -= 2 * t[x].lazy1;

        t[(x << 1) | 1].lazy1 += t[x].lazy1;
        t[(x << 1) | 1].xayd -= 2 * t[x].lazy1;
        t[(x << 1) | 1].xays -= 2 * t[x].lazy1;

        t[x].lazy1 = 0;
    }
}
// xzr只需要区间修改,查询最后的时候查询即可
void changing_xay(int x,int pos,int length){
    // y = -x + b
    // x + y = b 此时D = 2
    if(t[x].xayd <= pos) return; // 无法修改
    if(t[x].xays > pos) {
        // 全体都可移动
        t[x].lazy2 += length;
        t[x].xmyd += 2 * length;
        t[x].xmys += 2 * length;
        return;
    }
    pushdown(x);
    changing_xay(x << 1,pos,length);
    changing_xay((x << 1) | 1,pos,length);
    pushup(x);       
}
void changing_xmy(int x,int pos,int length) {
    // y = x + b
    // x - y = -b
    // 此时 D = 1
    if(t[x].xmys > pos) return; // 无法修改
    if(t[x].xmyd <= pos) {
        // 全体都可移动
        t[x].lazy1 += length;
        t[x].xayd -= 2 * length;
        t[x].xays -= 2 * length;
        return;
    }
    pushdown(x);
    changing_xmy(x << 1,pos,length);
    changing_xmy((x << 1) | 1,pos,length);
    pushup(x);      
}

int ans[N];
void getting(int x,int l,int r) {
    if(t[x].nowx) {
        // 根节点
        // t[x].xayd - ((t[x].xmyd + t[x].xayd) >> 1);
        ans[l] = t[x].xayd - ((t[x].xmyd + t[x].xayd) >> 1);
        return;
    }
    pushdown(x);
    int mid = (l + r) >> 1;
    getting(x << 1,l,mid);
    getting((x << 1) | 1,mid + 1,r);
}

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    cin >> n >> q;
    for(int i = q; i >= 1; --i) { // 倒着读
        cin >> moves[i].x >> moves[i].d >> moves[i].l;
    }
    build(1,n,1);
    for(int i = 1; i <= q; ++i) { // 我为什么要倒着读?
        if(moves[i].d == 1) {
            changing_xmy(1,moves[i].x,moves[i].l);
        }else {
            changing_xay(1,moves[i].x,moves[i].l);
        }
    }
    getting(1,1,n);
    for(int i = 1; i <= n; ++i) {
        cout << -ans[i] << "\n";
    }
}
2024/9/16 17:59
加载中...