#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define endl "\n"
#define out(x) cout<< #x << " = " << x << endl
int n,q; ll s,t;
ll arr[200005], diff[200005], ans;
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>q>>s>>t;
for (int i=0;i<=n;i++) cin>>arr[i];
for (int i=1;i<=n;i++) {
diff[i] = arr[i] - arr[i-1];
if (diff[i] > 0) ans -= s*diff[i];
else ans -= t*diff[i];
}
//out(ans);
while(q--){
int i,j; ll x; cin>>i>>j>>x;
if (diff[i] > 0) ans += s*diff[i];
else ans += t*diff[i];
if (j!=n){
if (diff[j+1] > 0) ans += s*diff[j+1];
else ans += t*diff[j+1];
}
diff[i] += x; diff[j+1] -= x;
if (diff[i] > 0) ans -= s*diff[i];
else ans -= t*diff[i];
if (j!=n){
if (diff[j+1] > 0) ans -= s*diff[j+1];
else ans -= t*diff[j+1];
}
//cout<<"#";
cout<<ans<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
10264 KB |
Output is correct |
2 |
Correct |
102 ms |
10828 KB |
Output is correct |
3 |
Correct |
94 ms |
11456 KB |
Output is correct |
4 |
Correct |
96 ms |
10796 KB |
Output is correct |
5 |
Correct |
101 ms |
12008 KB |
Output is correct |
6 |
Correct |
82 ms |
10952 KB |
Output is correct |
7 |
Correct |
83 ms |
10944 KB |
Output is correct |
8 |
Correct |
96 ms |
11936 KB |
Output is correct |
9 |
Correct |
92 ms |
12112 KB |
Output is correct |
10 |
Correct |
96 ms |
10852 KB |
Output is correct |
11 |
Correct |
91 ms |
10936 KB |
Output is correct |
12 |
Correct |
79 ms |
11616 KB |
Output is correct |
13 |
Correct |
78 ms |
11832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
93 ms |
10264 KB |
Output is correct |
23 |
Correct |
102 ms |
10828 KB |
Output is correct |
24 |
Correct |
94 ms |
11456 KB |
Output is correct |
25 |
Correct |
96 ms |
10796 KB |
Output is correct |
26 |
Correct |
101 ms |
12008 KB |
Output is correct |
27 |
Correct |
82 ms |
10952 KB |
Output is correct |
28 |
Correct |
83 ms |
10944 KB |
Output is correct |
29 |
Correct |
96 ms |
11936 KB |
Output is correct |
30 |
Correct |
92 ms |
12112 KB |
Output is correct |
31 |
Correct |
96 ms |
10852 KB |
Output is correct |
32 |
Correct |
91 ms |
10936 KB |
Output is correct |
33 |
Correct |
79 ms |
11616 KB |
Output is correct |
34 |
Correct |
78 ms |
11832 KB |
Output is correct |
35 |
Correct |
132 ms |
10376 KB |
Output is correct |
36 |
Correct |
109 ms |
11832 KB |
Output is correct |
37 |
Correct |
113 ms |
12624 KB |
Output is correct |
38 |
Correct |
103 ms |
12448 KB |
Output is correct |
39 |
Correct |
159 ms |
12356 KB |
Output is correct |
40 |
Correct |
96 ms |
12340 KB |
Output is correct |
41 |
Correct |
137 ms |
12272 KB |
Output is correct |
42 |
Correct |
96 ms |
12364 KB |
Output is correct |
43 |
Correct |
134 ms |
11536 KB |
Output is correct |
44 |
Correct |
126 ms |
11988 KB |
Output is correct |
45 |
Correct |
93 ms |
12056 KB |
Output is correct |
46 |
Correct |
108 ms |
13136 KB |
Output is correct |
47 |
Correct |
85 ms |
11712 KB |
Output is correct |
48 |
Correct |
96 ms |
11656 KB |
Output is correct |
49 |
Correct |
83 ms |
10648 KB |
Output is correct |
50 |
Correct |
79 ms |
11416 KB |
Output is correct |
51 |
Correct |
81 ms |
11860 KB |
Output is correct |
52 |
Correct |
87 ms |
11588 KB |
Output is correct |