結果

問題 No.1000 Point Add and Array Add
ユーザー bal4ubal4u
提出日時 2020-02-29 22:13:08
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 2,034 bytes
コンパイル時間 900 ms
コンパイル使用メモリ 32,256 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-04-21 21:56:27
合計ジャッジ時間 2,870 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 52 ms
6,016 KB
testcase_17 AC 38 ms
5,376 KB
testcase_18 AC 71 ms
7,296 KB
testcase_19 AC 71 ms
7,168 KB
testcase_20 AC 40 ms
5,632 KB
testcase_21 AC 67 ms
5,376 KB
testcase_22 AC 62 ms
6,016 KB
testcase_23 AC 68 ms
6,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yuki 1000 Point Add and Array Add
// 2020.2.28 bal4u

#include <stdio.h>

typedef long long ll;

int getchar_unlocked(void);
int putchar_unlocked();
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {  // 整数の入力
	int n = 0; int c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(ll n) {
	int i;
	char ob[40];

	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) ob[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(ob[i]);
	}
}

typedef int INT;

// bit木 1-indexedに注意
// b[1..bw) に対して b[i] += v
void add(INT *b, int bw, int i, INT v) {
    while (i <= bw) b[i] += v, i += i & -i;
}

// b[1..bw) に対して b[i]++
void add1(INT *b, int bw, int i) {
    while (i <= bw) b[i]++, i += i & -i;
}

// b[1..bw) に対して sum(b[1]..b[i])
INT sum(int *b, int i) {
    INT s = 0;
    while (i > 0) s += b[i], i -= i & -i;
    return s;
}

#define MAX 200005
int bitn;
INT bitb[MAX], bitc[MAX];

// range_add: add x to [i,j)
void range_add(int i, int j, INT x) {
    add(bitb, bitn, i, -i*x), add(bitb, bitn, j, j*x);
    add(bitc, bitn, i, x),    add(bitc, bitn, j, -x);
}
void range_add1(int i, int j) {
    add(bitb, bitn, i, -i), add(bitb, bitn, j, j);
    add1(bitc, bitn, i),    add(bitc, bitn, j, -1);
}

// range_sum0: sum [0,i)
INT range_sum0(int i) {
    return sum(bitb, i) + sum(bitc, i)*i;
}
// range_sum: sum [i,j)
INT range_sum(int i, int j) {
    return range_sum0(j) - range_sum0(i);
}

#define MAX 200005
char C[MAX]; int X[MAX], Y[MAX];
int A[MAX];
ll B[MAX];

int main()
{
	int i, N, Q;

	N = in(), Q = in();
	for (i = 1; i <= N; ++i) A[i] = in();
	for (i = 0; i < Q; ++i) {
		C[i] = (gc() == 'B'), gc();
		X[i] = in(), Y[i] = in();
	}
	bitn = N+1;
	while (Q--) {
		if (C[Q]) range_add1(X[Q], Y[Q]+1);
		else B[X[Q]] += (ll)Y[Q] * range_sum(X[Q], X[Q]+1);
	}

	out(B[1] + (ll)A[1] * range_sum(1, 2));
	for (i = 2; i <= N; ++i) {
		pc(' ');
		out(B[i] + (ll)A[i] * range_sum(i, i+1));
	}
	pc('\n');
	return 0;
}
0