Submission #701897

# Submission time Handle Problem Language Result Execution time Memory
701897 2023-02-22T09:57:16 Z tamthegod Foehn Phenomena (JOI17_foehn_phenomena) C++17
100 / 100
385 ms 18252 KB
// Make the best become better
// No room for laziness
#include<bits/stdc++.h>

#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, q, s, t;
int a[maxN];
int res = 0;
int st[4 * maxN], lazy[4 * maxN];
void down(int id)
{
    int t = lazy[id];
    lazy[id] = 0;
    st[id * 2] += t;
    lazy[id * 2] += t;
    st[id * 2 + 1] += t;
    lazy[id * 2 + 1] += t;
}
void build(int id, int l, int r)
{
    if(l == r)
    {
        st[id] = a[l];
        return;
    }
    int mid = (l + r) / 2;
    build(id * 2, l, mid);
    build(id * 2 + 1, mid + 1, r);
}
void update(int id, int l, int r, int u, int v, int val)
{
    if(l > v || r < u) return;
    if(l >= u && r <= v)
    {
        st[id] += val;
        lazy[id] += val;
        return;
    }
    int mid = (l + r) / 2;
    down(id);
    update(id * 2, l, mid, u, v, val);
    update(id * 2 + 1, mid + 1, r, u, v, val);
}
int get(int id, int l, int r, int pos)
{
    if(l == r) return st[id];
    int mid = (l + r) / 2;
    down(id);
    if(pos <= mid) return get(id * 2, l, mid, pos);
    return get(id * 2 + 1, mid + 1, r, pos);
}
void ReadInput()
{
    cin >> n >> q >> s >> t;
    for(int i=0; i<=n; i++)
        cin >> a[i];
    for(int i=1; i<=n; i++)
    {
        if(a[i] >= a[i - 1]) res -= (a[i] - a[i - 1]) * s;
        else res += (a[i - 1] - a[i]) * t;
    }
}
void Solve()
{
    build(1, 0, n);
    while(q--)
    {
        int l, r, x;
        cin >> l >> r >> x;
        int val1 = get(1, 0, n, l), val2 = get(1, 0, n, l - 1);
        if(val1 >= val2) res += s * (val1 - val2);
        else res -= t * (val2 - val1);
        if(r < n)
        {
            int val1 = get(1, 0, n, r), val2 = get(1, 0, n, r + 1);
            if(val2 >= val1) res += s * (val2 - val1);
            else res -= t * (val1 - val2);
        }
        update(1, 0, n, l, r, x);
        val1 = get(1, 0, n, l), val2 = get(1, 0, n, l - 1);
        if(val1 >= val2) res -= s * (val1 - val2);
        else res += t * (val2 - val1);
        if(r < n)
        {
            int val1 = get(1, 0, n, r), val2 = get(1, 0, n, r + 1);
            if(val2 >= val1) res -= s * (val2 - val1);
            else res += t * (val1 - val2);
        }
        cout << res << '\n';
    }
}
int32_t main()
{
   // freopen("sol.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}

# Verdict Execution time Memory Grader output
1 Correct 3 ms 472 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 3 ms 500 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 3 ms 480 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 476 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 3 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 377 ms 15752 KB Output is correct
2 Correct 364 ms 16332 KB Output is correct
3 Correct 370 ms 16928 KB Output is correct
4 Correct 377 ms 16152 KB Output is correct
5 Correct 384 ms 16996 KB Output is correct
6 Correct 158 ms 12288 KB Output is correct
7 Correct 154 ms 12132 KB Output is correct
8 Correct 303 ms 17300 KB Output is correct
9 Correct 304 ms 17484 KB Output is correct
10 Correct 310 ms 16468 KB Output is correct
11 Correct 198 ms 12236 KB Output is correct
12 Correct 154 ms 12668 KB Output is correct
13 Correct 152 ms 13032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 472 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 3 ms 500 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 3 ms 480 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 476 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 3 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 377 ms 15752 KB Output is correct
23 Correct 364 ms 16332 KB Output is correct
24 Correct 370 ms 16928 KB Output is correct
25 Correct 377 ms 16152 KB Output is correct
26 Correct 384 ms 16996 KB Output is correct
27 Correct 158 ms 12288 KB Output is correct
28 Correct 154 ms 12132 KB Output is correct
29 Correct 303 ms 17300 KB Output is correct
30 Correct 304 ms 17484 KB Output is correct
31 Correct 310 ms 16468 KB Output is correct
32 Correct 198 ms 12236 KB Output is correct
33 Correct 154 ms 12668 KB Output is correct
34 Correct 152 ms 13032 KB Output is correct
35 Correct 367 ms 15812 KB Output is correct
36 Correct 365 ms 17236 KB Output is correct
37 Correct 372 ms 18252 KB Output is correct
38 Correct 363 ms 17864 KB Output is correct
39 Correct 375 ms 17936 KB Output is correct
40 Correct 362 ms 17944 KB Output is correct
41 Correct 372 ms 17836 KB Output is correct
42 Correct 385 ms 17860 KB Output is correct
43 Correct 369 ms 17100 KB Output is correct
44 Correct 383 ms 17480 KB Output is correct
45 Correct 364 ms 17272 KB Output is correct
46 Correct 375 ms 17996 KB Output is correct
47 Correct 157 ms 12620 KB Output is correct
48 Correct 180 ms 12748 KB Output is correct
49 Correct 356 ms 16812 KB Output is correct
50 Correct 202 ms 12620 KB Output is correct
51 Correct 153 ms 12532 KB Output is correct
52 Correct 230 ms 12628 KB Output is correct