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 <random>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((x).size())
typedef long long ll;
using ull = unsigned long long;
using namespace std;
mt19937 rnd(348502);
ll mod1 = 998244353;
ll mod = 1e9 + 7;
const ll N = 200005;
int a[N];
ll s[4 * N];
void build(int p, int lp, int rp)
{
if (lp == rp)
{
s[p] = a[lp];
return;
}
int m = (lp + rp) / 2;
build(p * 2, lp, m);
build(p * 2 + 1, m + 1, rp);
}
ll ss, tt;
void update(int p ,int lp, int rp, int l, int r, int x)
{
if (l > r)return;
if (lp == l && rp == r)
{
s[p] += x;
return;
}
int m = (lp + rp) / 2;
update(p * 2, lp, m, l, min(r, m), x);
update(p * 2 + 1, m + 1, rp, max(m + 1, l), r, x);
}
ll get_arj(int p, int lp, int rp, int ind)
{
if (lp == rp)return s[p];
int m = (lp + rp) / 2;
if (ind <= m)
return get_arj(p * 2, lp, m, ind) + s[p];
else
return get_arj(p * 2 + 1, m + 1, rp, ind) + s[p];
}
int n;
ll get(int i)
{
ll x = get_arj(1, 0, n, i);
ll y = get_arj(1, 0, n, i + 1);
if(x < y)
return -(y - x) * ss;
return (x - y) * tt;
}
void solve()
{
int i, j, x, y, q;
cin >> n >> q >> ss >> tt;
for (i = 0; i <= n; i++)
{
cin >> a[i];
}
build(1, 0, n);
ll ans = 0;
for ( i = 0; i < n; i++)
{
ans += get(i);
}
for (i = 0; i < q; i++)
{
int l, r;
cin >> l >> r >> x;
ans -= get(l - 1);
ans -= get(r);
update(1, 0, n, l, r, x);
ans += get(l - 1);
ans += get(r);
cout << ans << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll tt = 1;
//cin >> tt;
while (tt--) {
solve();
}
return 0;
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'void solve()':
foehn_phenomena.cpp:82:12: warning: unused variable 'j' [-Wunused-variable]
82 | int i, j, x, y, q;
| ^
foehn_phenomena.cpp:82:18: warning: unused variable 'y' [-Wunused-variable]
82 | int i, j, x, y, q;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |