#include <bits/stdc++.h>
#define inf 2000000000
#define N 2050
using namespace std;
int n, q, S, T, A[N], bit[N], ans;
void upd(int l, int r, int x)
{
if(1 <= l && l <= n + 1) for(int i = l; i < N; i += (i&-i)) bit[i] += x;
if(1 <= r && r <= n + 1) for(int i = r + 1; i < N; i += (i&-i)) bit[i] -= x;
}
int query(int x)
{
int aux = 0;
if(x <= 0 || x > n + 1) return inf;
for(int i = x; i > 0; i -= (i&-i)) aux += bit[i];
return aux;
}
main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>q>>S>>T;
for(int i = 1; i <= n + 1; i++) cin>>A[i], upd(i, i, A[i]);
for(int i = 1; i <= n; i++) ans += (A[i] <= A[i + 1] ? (- A[i + 1] + A[i])*S : (A[i] - A[i + 1])*T);
for(int i = 1; i <= q; i++)
{
int li, ri, xi;
cin>>li>>ri>>xi;
li ++, ri ++;
int Hl = query(li);
int Hr = query(ri);
int H_depois = query(ri + 1);
int H_antes = query(li - 1);
upd(li, ri, xi);
int dl = 0, dr = 0;
if(H_antes != inf && H_antes <= Hl) dl -= abs(Hl - H_antes)*S ;
else if(H_antes != inf) dl += abs(Hl - H_antes)*T;
if(Hr <= H_depois && H_depois != inf) dr -= abs(H_depois - Hr)*S ;
else if(H_depois != inf) dr += abs(H_depois - Hr)*T;
ans = ans - dl - dr;
//cout<<"H :: "<<H_antes<<" "<<H_depois<<"\n";
//cout<<"DIMINUINDO "<<dl<<" "<<dr<<"\n";
Hl += xi, Hr += xi;
dl = 0, dr = 0;
if(H_antes <= Hl&& H_antes != inf) dl -= abs(Hl - H_antes)*S ;
else if(H_antes != inf) dl += abs(Hl - H_antes)*T;
if(Hr <= H_depois && H_depois != inf) dr -= abs(H_depois - Hr)*S ;
else if(H_depois != inf) dr += abs(H_depois - Hr)*T;
ans += dl + dr;
//cout<<"ADICIONANDO "<<dl<<" "<<dr<<"\n";
cout<<ans<<"\n";
}
}
Compilation message
foehn_phenomena.cpp:26:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
2192 KB |
Execution killed because of forbidden syscall writev (20) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
2192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
2192 KB |
Execution killed because of forbidden syscall writev (20) |
2 |
Halted |
0 ms |
0 KB |
- |