제출 #1331541

#제출 시각아이디문제언어결과실행 시간메모리
1331541adscodingFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
250 ms9796 KiB
#include <bits/stdc++.h>
#define time() cerr << 1.0 * clock() / CLOCKS_PER_SEC << "s\n"
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i)
#define FORLL(i, a, b) for (ll i = a, _b = b; i <= _b; ++i)
#define FORDLL(i, a, b) for (ll i = a, _b = b; i >= _b; --i)
#define all(x) x.begin(), x.end()
#define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void __print_one(const char *&s, const T &x)
{
    while (*s == ' ') ++s;
    const char *p = s;
    int bal = 0;
    while (*s)
    {
        if (*s == '(') ++bal;
        else if (*s == ')') --bal;
        else if (*s == ',' && bal == 0) break;
        ++s;
    }
    cerr.write(p, s - p) << " = " << x;
    if (*s == ',')
    {
        cerr << "  ,  ";
        ++s;
    }
}

template<typename... Args>
void debug(const char *s, Args... args)
{
    cerr << "[  ";
    int dummy[] = { 0 , (__print_one(s, args), 0)... };
    (void)dummy;
    cerr << "  ]\n\n";
}

template<class X>
bool maximize(X &a, X b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}


template<class X>
bool minimize(X &a, X b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

// -----------------------------------------------------------------

const int maxn = 2e5 + 15;
int n, q;
ll S, T, a[maxn], seg[maxn << 2];

// -----------------------------------------------------------------

void push(int id)
{
    seg[id << 1] += seg[id];
    seg[id << 1 | 1] += seg[id];
    seg[id] = 0;
}

void upd(int id, int l, int r, int u, int v, ll val)
{
    if (l > v || r < u) return;
    if (l >= u && r <= v) return seg[id] += val, void();
    int mid = l + r >> 1;
    push(id);
    upd(id << 1, l, mid, u, v, val);
    upd(id << 1 | 1, mid + 1, r, u, v, val);
}

ll get(int id, int l, int r, int pos)
{
    if (l == r) return seg[id];
    int mid = l + r >> 1;
    push(id);
    if (pos <= mid) return get(id << 1, l, mid, pos);
    return get(id << 1 | 1, mid + 1, r, pos);
}

ll get(int pos) {return get(1, 0, n, pos);}

ll calc_cost(ll x, ll y)
{
    if (x < y) return (x - y) * S;
    return (x - y) * T;
}

void solve()
{
    cin >> n >> q >> S >> T;
    FOR(i, 0, n)
        cin >> a[i];

    ll res = 0;
    FOR(i, 0, n - 1)
    {
        res += calc_cost(a[i], a[i + 1]);
//        dbg(a[i], a[i + 1], calc_cost(a[i], a[i + 1]));
    }

    FOR(i, 1, n)
        upd(1, 0, n, i, i, a[i]);

    while (q--)
    {
        int l, r; ll val; cin >> l >> r >> val;
        if (l > r)
        {
            cout << res << '\n';
            continue;
        }

        ll oldL = get(l), oldR = get(r);
        upd(1, 0, n, l, r, val);
        ll curL = oldL + val, curR = oldR + val;

        if (l > 0)
        {
            ll prevL = get(l - 1);
            res -= calc_cost(prevL, oldL);
            res += calc_cost(prevL, curL);
        }
        if (r < n)
        {
            ll prevR = get(r + 1);
            res -= calc_cost(oldR, prevR);
            res += calc_cost(curR, prevR);
        }

        cout << res << '\n';
    }
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define TASK "test"
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        freopen(TASK".OUT", "w", stdout);
    }
    solve();
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:167:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  167 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:168:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  168 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...