Submission #69357

#TimeUsernameProblemLanguageResultExecution timeMemory
69357MrTEKFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
273 ms168888 KiB
#include <bits/stdc++.h>

using namespace std;
#define mp make_pair
#define pb push_back
#define len(a) (int)a.size()
#define fi first
#define sc second
#define d1(w) cerr<<#w<<":"<<w<<endl;
#define d2(w,c) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<endl;
#define d3(w,c,z) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<" "<<#z<<":"<<z<<endl;
#define left isc+isc
#define right isc+isc+1
#define mid (l+r)/2
#define FAfi_IO ios_base::sync_with_fidio(false);
#define escl '\n'

typedef long long int ll;

const int maxn = 620;
const long long LINF = 1e18;
const int LOG = 31;
const int INF = 1e9;
const int N = 2e5 + 5;
const int M = 1e4 + 5;
const int SQ = 350;
const int MOD = 998244353;

typedef long long int lli;
typedef pair<int,int> pii;

int n,q,s,t,x[N];
long long ans,y[N];

int main() {

	scanf("%d %d %d %d",&n,&q,&s,&t);

	for (int i = 0 ; i <= n ; i++) scanf("%d",&x[i]);

	for (int i = 1 ; i <= n ; i++) y[i] = x[i] - x[i - 1];

	for (int i = 1 ; i <= n ; i++) ans += y[i] >= 0 ? s * y[i] : t * y[i];

	while (q--) {
		int l,r,k;
		scanf("%d %d %d",&l,&r,&k);
		if (l > 0) {
			ans -= y[l] >= 0 ? s * y[l] : t * y[l];
			y[l] += k;
			ans += y[l] >= 0 ? s * y[l] : t * y[l];
		}
		if (r < n) {
			ans -= y[r + 1] >= 0 ? s * y[r + 1] : t * y[r + 1];
			y[r + 1] -= k;
			ans += y[r + 1] >= 0 ? s * y[r + 1] : t * y[r + 1];			
		}
		printf("%lld\n",-ans);
	}

	return 0;
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d %d",&n,&q,&s,&t);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:39:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0 ; i <= n ; i++) scanf("%d",&x[i]);
                                 ~~~~~^~~~~~~~~~~~
foehn_phenomena.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&l,&r,&k);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...