제출 #493101

#제출 시각아이디문제언어결과실행 시간메모리
493101BiazFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
128 ms11700 KiB
#include <bits/stdc++.h>
#define int long long
//#define double long double
#define Nanase_Kurumi_aka_menhera_chan_is_mine ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi pair<int, int>
#define ALL(i) i.begin(),i.end()
#define gcd(i,j) __gcd(i,j)
#define fi first
#define se second
#define eps 0.00000001
#define ist insert
#define DNE nullptr
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC optimize("O2")
int max(int x,int y){return x>=y?x:y;}
int min(int x,int y){return x>=y?y:x;}
using namespace std;
typedef int ll;
const int N=200005;
const int M=1000005;
const int MOD=1000000007;//998244353;
const int INF=1000000000000000000;//2147483647;

int n,q,S,T;
int a[N],b[N];
/*int calc1(int x,int y){
    if (x<0&&y>0)
        return abs(x)*T+y*S;
    else if (y<0)
        return abs(y-x)*T;
    else return (y-x)*S;
}
int calc2(int x,int y){
    if (y<0&&x>0)
        return abs(y)*T+x*S;
    else if (x<0)
        return abs(x-y)*T;
    else
}*/
inline void sol(){
    cin >>n>>q>>S>>T;
    for (int i=0;i<=n;i++)
        cin >>a[i];
    for (int i=1;i<=n;i++)
        b[i]=a[i]-a[i-1];
    int res=0;
    for (int i=1;i<=n;i++)
        if (a[i]>a[i-1])
            res+=(a[i]-a[i-1])*S;
        else res-=(a[i-1]-a[i])*T;
    for (int i=0,l,r,x;i<q;i++){
        cin >>l>>r>>x;
        if (b[l]<0) res-=b[l]*T;
        else res-=b[l]*S;
        if (r!=n){
            if (b[r+1]<0) res-=b[r+1]*T;
            else res-=b[r+1]*S;
        }
        b[l]+=x;
        if (b[l]<0) res+=b[l]*T;
        else res+=b[l]*S;
        b[r+1]-=x;
        if (r!=n){
            if (b[r+1]<0) res+=b[r+1]*T;
            else res+=b[r+1]*S;
        }
        //for (int j=1;j<=n;j++) cout <<b[j]<<' ';
        cout <<-res<<'\n';
    }
}
signed main(){
    Nanase_Kurumi_aka_menhera_chan_is_mine
    int _=1;
    //cin >>_;
    while (_--) sol();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...