#include <bits/stdc++.h>
using namespace std;
int a[200005],b[200005];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,q,s,t;
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 poz=0,neg=0;
for(int i=1;i<=n;i++)
{
if(b[i]>=0)
poz+=b[i];
else
neg-=b[i];
}
while(q--)
{
int l,r,x;
cin>>l>>r>>x;
//L
if(x==0)
continue;
if(b[l]>=0)
{
if(x>=0)
{
poz+=x;
b[l]+=x;
}
else
{
if(b[l]+x<0)
{
poz-=b[l];
neg-=b[l]+x;
b[l]+=x;
}
if(b[l]+x>=0)
{
b[l]+=x;
poz+=x;
}
}
}
else
{
if(x<=0)
{
b[l]+=x;
neg-=x;
}
else
{
if(b[l]+x>0)
{
neg+=b[l];
poz+=x+b[l];
b[l]+=x;
}
if(b[l]+x<=0)
{
b[l]+=x;
neg-=x;
}
}
}
if(r==n)
goto ispis;
x=0-x;
r++;
if(b[r]>=0)
{
if(x>=0)
{
poz+=x;
b[r]+=x;
}
else
{
if(b[r]+x<0)
{
poz-=b[r];
neg-=b[r]+x;
b[r]+=x;
}
if(b[r]+x>=0)
{
b[r]+=x;
poz+=x;
}
}
}
else
{
if(x<=0)
{
b[r]+=x;
neg-=x;
}
else
{
if(b[r]+x>0)
{
neg+=b[r];
poz+=x+b[r];
b[r]+=x;
}
if(b[r]+x<=0)
{
b[r]+=x;
neg-=x;
}
}
}
ispis:
cout<<t*neg-s*poz<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
620 KB |
Output is correct |
2 |
Incorrect |
6 ms |
492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
538 ms |
8828 KB |
Output is correct |
2 |
Correct |
550 ms |
9452 KB |
Output is correct |
3 |
Incorrect |
547 ms |
9452 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
620 KB |
Output is correct |
2 |
Incorrect |
6 ms |
492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |