Submission #33251

# Submission time Handle Problem Language Result Execution time Memory
33251 2017-10-23T07:26:15 Z UncleGrandpa925 Foehn Phenomena (JOI17_foehn_phenomena) C++14
0 / 100
93 ms 28756 KB
/*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 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;

int acc(int p) {
	return IT.get(1, 1, n, p, p);
}

int curans = 0;
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> q >> S >> T; n++;
	for (int i = 1; i <= n; i++) cin >> a[i], IT.update(1, 1, n, i, i, a[i]);
	for (int i = 2; i <= n; i++) {
		if (a[i - 1] < a[i]) curans -= S * abs(a[i] - a[i - 1]);
		else curans += T * abs(a[i] - a[i - 1]);
	}
	for (int i = 1; i <= q; i++) {
		int l, r, val;
		cin >> l >> r >> val;
		l++; r++;
		if (l != 1) {
			int x = acc(l - 1); int y = acc(l);
			if (x < y) curans += S * abs(x - y);
			else curans -= T * abs(x - y);
		}
		if (r != n) {
			int x = acc(r); int y = acc(r + 1);
			if (x < y) curans += S * abs(x - y);
			else curans -= T * abs(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 * abs(x - y);
			else curans += T * abs(x - y);
		}
		if (r != n) {
			int x = acc(r); int y = acc(r + 1);
			if (x < y) curans -= S * abs(x - y);
			else curans += T * abs(x - y);
		}
		cout << curans << endl;
	}
}

Compilation message

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;
                    ^
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 28756 KB Execution killed because of forbidden syscall writev (20)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 93 ms 28756 KB Execution killed because of forbidden syscall writev (20)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 28756 KB Execution killed because of forbidden syscall writev (20)
2 Halted 0 ms 0 KB -