제출 #51495

#제출 시각아이디문제언어결과실행 시간메모리
51495Flying_dragon_02Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
177 ms7528 KiB
#include<bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<long long,long long> ii;

long long n,q;
long long a[200005],sum,total,s,t,b[200005];

int main(){
    cin.tie(0),cout.tie(0),ios::sync_with_stdio(0);
    cin >> n >> q >> s >> t;
    for(int i = 0;i<=n;i++)
        cin >> a[i];

    long long ans = 0;
    for(int i = 1;i<=n;i++){
        b[i] = a[i] - a[i - 1];
        if (b[i] >= 0) total -= b[i] * s;
        else total -= b[i] * t;
    }
    while(q--){
        long long l,r;
        long long x;
        cin >> l >> r >> x;
        if (b[l] >= 0) total += b[l] * s;
        else total += b[l] * t;
        b[l] += x;
        if (b[l] >= 0) total -= b[l] * s;
        else total -= b[l] * t;

        if (r < n) {
            if (b[r + 1] >= 0) total += b[r + 1] * s;
            else total += b[r + 1] * t;

            b[r + 1] -= x;
            if (b[r + 1] >= 0) total -= b[r + 1] * s;
            else total -= b[r + 1] * t;
        }
        cout<<total<<"\n";
    }
}

컴파일 시 표준 에러 (stderr) 메시지

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:21:15: warning: unused variable 'ans' [-Wunused-variable]
     long long ans = 0;
               ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...