This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 1000000007
#define pb push_back
#define mid(l, r) ((l)+(r))/2
#define len(a) (a).length()
#define sz(a) (a).size()
#define xx first
#define yy second
#define inf int(2e9)
#define ff(i, a, b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i, a, b) for(int (i) = (a); (i) >= (b); --(i))
#define maxn 200005
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<class T>
void print(const T niz[], const int siz)
{
for(int i=0;i<siz;i++)
cout << niz[i] << " ";
cout << endl;
}
int n,q;
ll s,t;
ll niz[maxn];
ll dif[maxn];
ll res;
int main()
{
ios_base::sync_with_stdio(false);
cin >> n >> q >> s >> t;
ff(i,0,n)cin >> niz[i];
ff(i,0,n-1){
dif[i] = niz[i + 1] - niz[i];
if(dif[i] > 0)res -= dif[i]*s;
else res -= dif[i]*t;
}
while(q--){
int l,r;
ll x;
cin >> l >> r >> x;
if(dif[l-1] > 0)res += dif[l-1]*s;
else res += dif[l-1]*t;
dif[l-1] += x;
if(dif[l-1] > 0)res -= dif[l-1]*s;
else res -= dif[l-1]*t;
if(r != n){
if(dif[r] > 0)res += dif[r]*s;
else res += dif[r]*t;
dif[r] -= x;
if(dif[r] > 0)res -= dif[r]*s;
else res -= dif[r]*t;
}
cout << res << endl;
}
return 0;
}
Compilation message (stderr)
foehn_phenomena.cpp:2:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/stack:200000000")
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |