제출 #553978

#제출 시각아이디문제언어결과실행 시간메모리
553978AA_SurelyFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
197 ms15796 KiB
#include <bits/stdc++.h>

#define FOR(i,x,n) 	for(int i=x; i<n; i++)
#define F0R(i,n) 	FOR(i,0,n)
#define ROF(i,x,n) 	for(int i=n-1; i>=x; i--)
#define R0F(i,n) 	ROF(i,0,n)

#define WTF 		cout << "WTF" << endl

#define IOS 		ios::sync_with_stdio(false); cin.tie(0)
#define F 			first
#define S	 		second
#define pb 			push_back

#define ALL(x) 		x.begin(), x.end()
#define RALL(x) 	x.rbegin(), x.rend()

using namespace std;
typedef long long 		LL;

typedef pair<int, int> 	PII;
typedef pair<LL, LL> 	PLL;

typedef vector<int> 	VI;
typedef vector<LL> 		VLL;
typedef vector<PII> 	VPII;
typedef vector<PLL> 	VPLL;

const int N = 2e5 + 7;
const int ALPHA = 27;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int LOG = 22;

#define lc now << 1
#define rc now << 1 | 1

LL n, q, s, t;
LL ns[N], tree[N << 2];

#define endl '\n'

LL build(int now = 1, int ls = 0, int rs = n - 1) {
    if (ls == rs) return tree[now] = ns[ls] * (ns[ls] < 0 ? -t : -s);
    int mid = (ls + rs) >> 1;
    return tree[now] = build(lc, ls, mid) + build(rc, mid + 1, rs);
}

void change(int id, int now = 1, int ls = 0, int rs = n - 1) {
    if (ls == rs) {
        tree[now] = ns[ls] * (ns[ls] < 0 ? -t : -s);
        return;
    }

    int mid = (ls + rs) >> 1;
    if (id <= mid) change(id, lc, ls, mid);
    else change(id, rc, mid + 1, rs);

    tree[now] = tree[lc] + tree[rc];

    return;
}

int main() {
    IOS;
        
    cin >> n >> q >> s >> t;

    F0R(i, n + 1) cin >> ns[i];
    F0R(i, n) ns[i] = ns[i + 1] - ns[i];

    build();

    LL lo, hi, v;
    while(q--) {
        cin >> lo >> hi >> v;
        lo--;

        ns[lo] += v;
        if (hi < n) ns[hi] -= v;

        change(lo);
        if (hi < n) change(hi);

        cout << tree[1] << endl;
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...