Submission #173412

#TimeUsernameProblemLanguageResultExecution timeMemory
173412dennisstarFoehn Phenomena (JOI17_foehn_phenomena)C++11
0 / 100
647 ms16920 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ryan bear
#define all(V) ((V).begin()), ((V).end())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef vector<int> vim;
typedef vector<ll> vlm;

int N, Q; ll S, T;
ll A[1000010];
int L, R; ll X, now;

struct dt {
	ll ar[(1<<22)], lz[(1<<22)];
	void init() { for (int i=0; i<=N; i++) upd(i, i, A[i]); }
	int get(int t, int s, int e, int ind) {
		spread(ind);
		if (s==e) return ar[ind];
		int md=(s+e)/2;
		if (t<=md) return get(t, s, md, ind*2);
		else return get(t, md+1, e, ind*2+1);
	}
	void upd(int is, int ie, int s, int e, int ind, ll val) {
		if (s>e) return ;
		if (is<=s&&e<=ie) { lz[ind]=val; return ; }
		int md=(s+e)/2;
		if (is<=md) upd(is, ie, s, md, ind*2, val);
		if (md+1<=ie) upd(is, ie, md+1, e, ind*2+1, val);
	}
	void spread(int i) {
		if (i<(1<<21)) lz[i*2]+=lz[i], lz[i*2+1]+=lz[i];
		ar[i]+=lz[i]; lz[i]=0;
	}
	void upd(int is, int ie, ll val) { upd(is, ie, 0, N, 1, val); }
	int get(int t) { return get(t, 0, N, 1); }
}DS;

ll f(ll a, ll b) { return (a-b)*(a<b?S:T); }

int main() {
	scanf("%d %d %lld %lld", &N, &Q, &S, &T);
	for (int i=0; i<=N; i++) scanf("%lld", &A[i]);
	for (int i=1; i<=N; i++) now+=f(A[i-1], A[i]);
	DS.init();
	ll a, b;
	for (int i=0; i<Q; i++) {
		scanf("%d %d %lld", &L, &R, &X);
		
		a=DS.get(L-1); b=DS.get(L);
		now-=f(a, b);
		if (R!=N) {
			a=DS.get(R); b=DS.get(R+1);
			now-=f(a, b);
		}

		DS.upd(L, R, X);

		a=DS.get(L-1); b=DS.get(L);
		now+=f(a, b);
		if (R!=N) {
			a=DS.get(R); b=DS.get(R+1);
			now+=f(a, b);
		}

		printf("%lld\n", now);
	}
	return 0;
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %lld %lld", &N, &Q, &S, &T);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:47:32: 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("%lld", &A[i]);
                           ~~~~~^~~~~~~~~~~~~~~
foehn_phenomena.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %lld", &L, &R, &X);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...