Submission #982368

# Submission time Handle Problem Language Result Execution time Memory
982368 2024-05-14T07:30:30 Z Amirreza_Fakhri Foehn Phenomena (JOI17_foehn_phenomena) C++17
0 / 100
123 ms 11044 KB
// In the name of the God
#include <bits/stdc++.h>
#define ll long long
// #define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;

// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")

const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 2e5+5;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, q, s, t, a[maxn], d[maxn], seg[maxn*2];

int f(int x, int y) {
    if (x < y) return -s*(y-x);
    return t*(x-y);
}

void upd(int l, int r, int x) {
    for (l += n+1, r += n+1; l < r; l /= 2, r /= 2) {
        if (l&1) seg[l++] += x;
        if (r&1) seg[--r] += x;
    }
}

int get(int i) {
    int res = 0;
    for (i += n+1; i; i /= 2) res += seg[i];
    return res;
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> q >> s >> t;
    int ans = 0;
    cin >> a[0];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        ans += (d[i] = f(a[i-1], a[i]));
    }
    while (q--) {
        int l, r, x; cin >> l >> r >> x;
        upd(l, r+1, x);
        ans -= d[l]+d[r+1];
        ans += (d[l] = f(a[l-1]+get(l-1), a[l]+get(l)));
        if (r != n) ans += (d[r+1] = f(a[r]+get(r), a[r+1]+get(r+1)));
        cout << ans << '\n';
        // for (int i = 0; i <= n; i++) cout << a[i]+get(i) << ' ';
        // cout << '\n';
    }
    return 0;
}





/*
srand(time(0));
cout << (rand()%1900) + 1 << ' ' << (rand()%2)+5 << '\n';
*/






















# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Incorrect 2 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 123 ms 10300 KB Output is correct
2 Correct 121 ms 11044 KB Output is correct
3 Incorrect 115 ms 10984 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Incorrect 2 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -