比赛 2024暑假C班集训5 评测结果 AAAAAAAAAA
题目名称 焚风现象 最终得分 100
用户昵称 flyfree 运行时间 4.113 s
代码语言 C++ 内存使用 20.04 MiB
提交时间 2024-07-05 09:20:23
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN  1000005
ll a[MAXN],s1[MAXN],s2[MAXN];
ll n,m,s,t;
ll lowbit(ll idx){
    return idx&(-idx);
}
void ad_1(ll idx,ll h){
    while(idx<=n){
       s1[idx]+=h;
       idx+=lowbit(idx); 
    }
}
void ad_2(ll idx,ll h){
    while(idx<=n){
       s2[idx]+=h;
       idx+=lowbit(idx); 
    }
}
ll re_1(ll idx){
    ll ans=0;
    while(idx){
        ans+=s1[idx];
        idx-=lowbit(idx);
    }
    return ans;
}
ll re_2(ll idx){
    ll ans=0;
    while(idx){
        ans+=s2[idx];
        idx-=lowbit(idx);
    }
    return ans;
}
int main(){
    freopen("foehn.in","r",stdin);
    freopen("foehn.out","w",stdout);
    cin>>n>>m>>s>>t;
    cin>>a[0];
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]-a[i-1]>0){
            ad_1(i,a[i]-a[i-1]);
        }else{
            ad_2(i,a[i]-a[i-1]);
        }
    }
    for(int i=1;i<=m;i++){
        ll l,r,drth;
        cin>>l>>r>>drth;
        ll lz=re_1(l)+re_2(l);
        ll rz=re_1(r)+re_2(r);
        ll fst=re_1(l-1)+re_2(l-1);
        ll nxt=re_1(r+1)+re_2(r+1);
        if(lz-fst>0){
            if(drth<0&&drth<fst-lz){
                ad_2(l,drth+lz-fst);
                ad_1(l,fst-lz);
            }else ad_1(l,drth);
        }else{
            if(drth>0&&drth>fst-lz){
                ad_2(l,fst-lz);
                ad_1(l,drth+lz-fst);
            }else ad_2(l,drth);
        }
        if(nxt-rz>0){
            if(drth>0&&drth>nxt-rz){
                ad_1(r+1,rz-nxt);
                ad_2(r+1,-drth+nxt-rz);
            }else ad_1(r+1,-drth);
        }else{
            if(drth<0&&drth<nxt-rz){
                ad_2(r+1,rz-nxt);
                ad_1(r+1,-drth+nxt-rz);
            }else ad_2(r+1,-drth);
        }
        ll ans=-re_1(n)*s-re_2(n)*t;
        cout<<ans<<endl;
//        for(int j=1;j<=n;j++){
//            cout<<re_1(j)<<" ";
//        }
//        cout<<endl;
//        for(int j=1;j<=n;j++){
//            cout<<re_2(j)<<" "; 
//        }
//        cout<<endl;
    }
    return 0;
}