Submission #33270

#TimeUsernameProblemLanguageResultExecution timeMemory
33270UncleGrandpa925Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
999 ms28600 KiB
/*input
2 2 5 5
0 6 -1
1 1 4
1 2 8

3 5 1 2
0 4 1 8
1 2 2
1 1 -2
2 3 5
1 2 -1
1 3 5
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N 200005
#define bit(x,y) ((x>>y)&1LL)
#define show(x) cout << (#x) << ": " << x << endl;
#define ii pair<int,int>
ostream& operator << (ostream &os, vector<int>&x) {
	for (int i = 0; i < x.size(); i++) os << x[i] << sp;
	return os;
}
ostream& operator << (ostream &os, pair<int, int> x) {
	cout << x.fi << sp << x.se << sp;
	return os;
}
ostream& operator << (ostream &os, vector<pair<int, int> >&x) {
	for (int i = 0; i < x.size(); i++) os << x[i] << endl;
	return os;
}

int n, q, S, T;
int a[N];
int f[4 * N];
int lazy[4 * N];

class ITrangeSum {
private:
	int f[4 * N];
	int lazy[4 * N];
	void dolazy(int k, int l, int r) {
		if (lazy[k] == 0) return;
		f[k] += lazy[k] * (r - l + 1);
		if (l != r) {
			lazy[k * 2] += lazy[k];
			lazy[k * 2 + 1] += lazy[k];
		}
		lazy[k] = 0;
	}
public:
	void init(int k, int l, int r) {
		if (l == r) {
			f[k] = a[l];
			return;
		}
		int mid = (l + r) / 2;
		init(k * 2, l, mid); init(k * 2 + 1, mid + 1, r);
		f[k] = f[k * 2] + f[k * 2 + 1];
	}
	void update(int k, int l, int r, int L, int R, int val) {
		dolazy(k, l, r);
		if (r < L || R < l) return;
		if (L <= l && r <= R) {
			f[k] += val * (r - l + 1);
			if (l != r) {
				lazy[k * 2] += val;
				lazy[k * 2 + 1] += val;
			}
			return;
		}
		int mid = (l + r) / 2;
		update(k * 2, l, mid, L, R, val); update(k * 2 + 1, mid + 1, r, L, R, val);
		f[k] = f[k * 2] + f[k * 2 + 1];
	}
	int get(int k, int l, int r, int L, int R) {
		dolazy(k, l, r);
		if (r < L || R < l) return 0;
		if (L <= l && r <= R) return f[k];
		int mid = (l + r) / 2;
		return get(k * 2, l, mid, L, R) + get(k * 2 + 1, mid + 1, r, L, R);
	}
} IT;
#define acc(p) IT.get(1, 1, n, p, p)

int curans = 0;
signed main() {
	scanf("%lld %lld %lld %lld", &n, &q, &S, &T); n++;
	for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
	IT.init(1, 1, n);
	for (int i = 2; i <= n; i++) {
		if (a[i - 1] < a[i]) curans -= S * (a[i] - a[i - 1]);
		else curans += T * abs(a[i - 1] - a[i]);
	}
	for (int i = 1; i <= q; i++) {
		int l, r, val;
		scanf("%lld %lld %lld", &l, &r, &val);
		l++; r++;
		if (l != 1) {
			int x = acc(l - 1); int y = acc(l);
			if (x < y) curans += S * (y - x);
			else curans -= T * (x - y);
		}
		if (r != n) {
			int x = acc(r); int y = acc(r + 1);
			if (x < y) curans += S * (y - x);
			else curans -= T * (x - y);
		}
		IT.update(1, 1, n, l, r, val);
		if (l != 1) {
			int x = acc(l - 1); int y = acc(l);
			if (x < y) curans -= S * (y - x);
			else curans += T * (x - y);
		}
		if (r != n) {
			int x = acc(r); int y = acc(r + 1);
			if (x < y) curans -= S * (y - x);
			else curans += T * (x - y);
		}
		printf("%lld\n", curans);
	}
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<long long int>&)':
foehn_phenomena.cpp:48:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << sp;
                    ^
foehn_phenomena.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<std::pair<long long int, long long int> >&)':
foehn_phenomena.cpp:56:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << endl;
                    ^
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:115:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld %lld %lld", &n, &q, &S, &T); n++;
                                              ^
foehn_phenomena.cpp:116:51: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
                                                   ^
foehn_phenomena.cpp:124:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld", &l, &r, &val);
                                        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...