Submission #1260712

#TimeUsernameProblemLanguageResultExecution timeMemory
1260712tminhFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
61 ms6472 KiB
#include "bits/stdc++.h"
using namespace std;

#define task ""
#define ll long long
#define endl '\n'
#define fi first
#define se second
#define vall(a) (a).begin(), (a).end()
#define sze(a) (int)a.size()
#define pii pair<int, int>
#define pll pair<ll, ll>


#define ep emplace_back
#define pb push_back
#define pf push_front


const ll mod = 1e9 + 7;
const int N = 1e6 + 5;
const ll oo = 1e18;

bool START;

int n, a[N], q;
ll d[N];
ll s, t;


inline void solve() {
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		d[i] = a[i] - a[i - 1];
		ans -= (d[i] > 0 ? d[i] * s : d[i] * t);
		
		// cout << d[i] << " ";
	}
	// cout << endl;
	
	// cout << ans << endl;
	while(q--) {
		int l, r;
		ll x;
		cin >> l >> r >> x;
		if (l > 0) {
			ans += (d[l] > 0 ? d[l] * s : d[l] * t);
			d[l] += x;
			ans -= (d[l] > 0 ? d[l] * s : d[l] * t);
		}
		if (r < n) {
			ans += (d[r + 1] > 0 ? d[r + 1] * s : d[r + 1] * t);
			d[r + 1] -= x;
			ans -= (d[r + 1] > 0 ? d[r + 1] * s : d[r + 1] * t);
		}
		cout << ans << endl;
	}
}


inline void input() {
    cin >> n >> q >> s >> t;
    for (int i = 0; i <= n; ++i) cin >> a[i];
    return solve();
}
bool END;

int main() {
    if(fopen(task ".inp", "r")) {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    input();
    
    
    cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << 's' << endl;
    cerr << "Memory: " << fabs ((&END - &START)) / 1048576.0 << "MB\n";
    return 0;
}

Compilation message (stderr)

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