比赛 2024暑假C班集训5 评测结果 AAAAAAAAAA
题目名称 焚风现象 最终得分 100
用户昵称 darkMoon 运行时间 1.962 s
代码语言 C++ 内存使用 15.76 MiB
提交时间 2024-07-05 10:31:11
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define mp make_pair
using namespace std;
//#define fin cin
//#define fout cout
ifstream fin("foehn.in");
ofstream fout("foehn.out");
auto mread = [](){
    int x;
    fin >> x;
    return x;
};
const int N = 2e5 + 5;
int n = mread(), q = mread(), S = mread(), t = mread(), a[N], s[N * 5], lz[N * 5], ans;
void build(int x, int nl, int nr){
    if(nl == nr){
        s[x] = a[nl];
        return;
    }
    int mid = nl + nr >> 1;
    build(x << 1, nl, mid);
    build(x << 1 | 1, mid + 1, nr);
    return;
}
void pushup(int x){
    s[x] = s[x << 1] + s[x << 1 | 1];
    return;
}
void pushdown(int x, int len){
    if(lz[x] != 0){
        lz[x << 1] += lz[x];
        lz[x << 1 | 1] += lz[x];
        s[x << 1] += (len >> 1) * lz[x];
        s[x << 1 | 1] += (len >> 1) * lz[x];
        lz[x] = 0;
    }
    return;
}
void add(int x, int nl, int nr, int l, int r, int k){
    if(nl >= l && nr <= r){
        s[x] += (nr - nl + 1) * k;
        lz[x] += k;
        return;
    }
    pushdown(x, nr - nl + 1);
    int mid = nl + nr >> 1;
    if(mid >= l)
    add(x << 1, nl, mid, l, r, k);
    if(mid + 1 <= r)
    add(x << 1 | 1, mid + 1, nr, l, r, k);
    pushup(x);
    return;
}
int query(int x, int nl, int nr, int p){
//    printf("***\n");
    if(nl == nr){
        return s[x];
    }
    pushdown(x, nr - nl + 1);
    int mid = nl + nr >> 1;
    if(p <= mid){
        pushup(x);        
        return query(x << 1, nl, mid, p);
    }
    else{
        pushup(x);        
        return query(x << 1 | 1, mid + 1, nr, p);
    }

}
signed main(){
    for(int i = 0; i <= n; i ++)
    a[i] = mread();
    for(int i = 1; i <= n; i ++){
        if(a[i] > a[i - 1])
        ans -= (a[i] - a[i - 1]) * S;
        else if(a[i] < a[i - 1])
        ans -= (a[i] - a[i - 1]) * t;
//        printf("*** %lld %lld\n", a[i] - a[i - 1], ans);
    }
    build(1, 1, n);
//    printf("*** %lld\n", ans);
    for(int i = 1, l, r, x; i <= q; i ++){
        l = mread(), r = mread(), x = mread();
        int a, b, c, d, e, f;
        b = query(1, 1, n, l), c = query(1, 1, n, r);
        if(l == 1)
        a = 0;
        else
        a = query(1, 1, n, l - 1);
        if(r < n)
        d = query(1, 1, n, r + 1);
        else
        d = c;
        
        if(b > a)
        ans += (b - a) * S;
        else if(b < a)
        ans += (b - a) * t;
        if(d > c)
        ans += (d - c) * S;
        else if(d < c)
        ans += (d - c) * t;
        
        add(1, 1, n, l, r, x);
        e = b + x, f = c + x;
        if(r == n)
        d = f;
        
        if(e > a)
        ans -= (e - a) * S;
        else if(e < a)
        ans -= (e - a) * t;
        if(d > f)
        ans -= (d - f) * S;
        else if(d < f)
        ans -= (d - f) * t;
        
        fout << ans << "\n";
    }
}