結果

問題 No.1000 Point Add and Array Add
ユーザー AltTTTAltTTT
提出日時 2020-03-06 00:42:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 530 ms / 2,000 ms
コード長 4,353 bytes
コンパイル時間 1,327 ms
コンパイル使用メモリ 110,028 KB
実行使用メモリ 20,940 KB
最終ジャッジ日時 2024-04-22 03:37:37
合計ジャッジ時間 6,415 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 301 ms
18,560 KB
testcase_17 AC 274 ms
13,184 KB
testcase_18 AC 444 ms
20,736 KB
testcase_19 AC 446 ms
20,804 KB
testcase_20 AC 290 ms
20,736 KB
testcase_21 AC 530 ms
20,940 KB
testcase_22 AC 323 ms
20,752 KB
testcase_23 AC 513 ms
20,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <iomanip>
#include <climits>
#include <string>
#include <sstream>
#include <numeric>
#include <stack>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;
struct LSegT {
	int N;
	vector< int > node, lazy;
	LSegT(vector< int > &A) {
		int sz = A.size();
		N = 1;
		while (N < sz)
			N *= 2;
		node.resize(2 * N - 1);
		lazy.resize(2 * N - 1, 0);
		rep(i, sz) node[i + N - 1] = A[i];
		for (int i = N - 2; i >= 0; i--)
			node[i] = node[i * 2 + 1] + node[i * 2 + 2];
	}
	void eval(int k, int l, int r) {
		if (lazy[k] != 0) {
			node[k] += lazy[k];
			if (r - l > 1) {
				lazy[2 * k + 1] += lazy[k] / 2;
				lazy[2 * k + 2] += lazy[k] / 2;
			}
			lazy[k] = 0;
		}
	}
	void add(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
		if (r < 0)
			r = N;
		eval(k, l, r);
		if (b <= l || r <= a)
			return;
		if (a <= l && r <= b) {
			lazy[k] += (r - l) * x;
			eval(k, l, r);
		} else {
			add(a, b, x, 2 * k + 1, l, (l + r) / 2);
			add(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = node[2 * k + 1] + node[2 * k + 2];
		}
	}
	int sum(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)
			r = N;
		if (b <= l || r <= a)
			return 0;
		eval(k, l, r);
		if (a <= l && r <= b)
			return node[k];
		int vl = sum(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = sum(a, b, 2 * k + 2, (l + r) / 2, r);
		return vl + vr;
	}
};
int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> Q;
	vector< int > A(N);
	rep(i, N) cin >> A[i];
	vector< int > B(N, 0);
	vector< int > C(N, 0);
	LSegT lst(C);
	vector< pair< char, pii > > Query(Q);
	rep(i, Q) {
		cin >> Query[i].first >> Query[i].second.first >> Query[i].second.second;
		Query[i].second.first--;
		if (Query[i].first == 'B')
			Query[i].second.second--;
	}
	rep(i, Q) {
		if (Query[i].first == 'A')
			continue;
		lst.add(Query[i].second.first, Query[i].second.second + 1, 1);
	}
	rep(i, N) {
		B[i] += A[i] * lst.sum(i, i + 1);
	}
	rep(i, Q) {
		int x = Query[i].second.first, y = Query[i].second.second;
		if (Query[i].first == 'A') {
			B[x] += y * lst.sum(x, x + 1);
		} else {
			lst.add(x, y + 1, -1);
		}
	}
	rep(i, N) cout << B[i] << " ";
	cout << endl;
	return 0;
}
0