Submission #1150694

#TimeUsernameProblemLanguageResultExecution timeMemory
1150694nguynFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
62 ms7240 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ll long long 
#define F first
#define S second
#define pb push_back 
#define pii pair<int,int>

const int N = 2e5 + 5;

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

signed main(){
    ios_base::sync_with_stdio(false) ; 
    cin.tie(0) ; cout.tie(0) ; 
    if (fopen("INP.INP" ,"r")) {
        freopen("INP.INP" ,"r" , stdin) ;
        freopen("OUT.OUT" , "w" , stdout) ;
    }
    cin >> n >> q >> s >> t;
    int res = 0;  
    for (int i = 0; i <= n; i++) {
    	cin >> a[i];
    	if (i > 0) {
	    	d[i] = a[i] - a[i - 1];
	    	if (d[i] > 0) res -= d[i] * s;
	    	else res -= d[i] * t; 
    	}
    }
    while(q--) {
    	int l, r, k;
    	cin >> l >> r >> k; 
    	if (d[l] > 0) res += d[l] * s;
    	else res += d[l] * t; 
    	d[l] += k;   
    	if (d[l] > 0) res -= d[l] * s;
    	else res -= d[l] * t; 
    	if (r < n) {
    		if (d[r + 1] > 0) res += d[r + 1] * s;
    		else res += d[r + 1] * t;  
    		d[r + 1] -= k;
    		if (d[r + 1] > 0) res -= d[r + 1] * s;
    		else res -= d[r + 1] * t;   
    	}
    	 
    	cout << res << '\n'; 
    }
}

Compilation message (stderr)

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