結果

問題 No.1000 Point Add and Array Add
ユーザー daut-dlangdaut-dlang
提出日時 2020-02-28 22:49:19
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 376 ms / 2,000 ms
コード長 3,535 bytes
コンパイル時間 1,170 ms
コンパイル使用メモリ 113,240 KB
実行使用メモリ 45,348 KB
最終ジャッジ日時 2023-09-04 06:14:31
合計ジャッジ時間 6,234 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 253 ms
38,656 KB
testcase_17 AC 227 ms
26,856 KB
testcase_18 AC 369 ms
43,832 KB
testcase_19 AC 371 ms
45,348 KB
testcase_20 AC 280 ms
41,884 KB
testcase_21 AC 376 ms
44,840 KB
testcase_22 AC 318 ms
44,300 KB
testcase_23 AC 375 ms
44,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

struct SegTree(T, E)
{
	alias T delegate(T, E) G;
	alias T delegate(E, E) H;
	int n;
	G g; H h;
	T d1; E d0;
	T[] dat; E[] laz;
	this(int _n, G _g, H _h, T _d1, E _d0, T[] v = [])
	{
		g = _g;	h = _h;
		d1 = _d1; d0 = _d0;
		init(_n);
		if (_n == cast(int)v.length) build(_n, v);
	}
	void init(int _n)
	{
		n = 1;
		while (n < _n) n *= 2;
		dat.length = n; dat[] = d1;
		laz.length = 2*n-1; laz[] = d0;
	}
	void build(int _n, T[] v)
	{
		foreach (i; 0.._n) dat[i] = v[i];
	}
	void update(int a, int b, E x, int k, int l, int r)
	{
		if (r <= a || b <= l) return;
		if (a <= l && r <= b)
		{
			laz[k] = h(laz[k], x);
			return;
		}
		update(a, b, x, k*2+1, l, (l+r)/2);
		update(a, b, x, k*2+2, (l+r)/2, r);
	}
	void update(int a, int b, E x)
	{
		update(a, b, x, 0, 0, n);
	}
	T query(int k)
	{
		T c = dat[k];
		k += n-1;
		E x = laz[k];
		while (k > 0)
		{
			k = (k-1)/2;
			x = h(x,laz[k]);
		}
		return g(c,x);
	}
}

void main()
{
	auto N = RD;
	auto Q = RD;
	auto A = RDA;
	auto c = new string[](Q);
	auto xy = new int[][](Q);
	auto imos = new long[](N+1);
	foreach (i; 0..Q)
	{
		c[i] = RD!string;
		xy[i] = [RD!int-1, RD!int];
		if (c[i][0] == 'B')
		{
			--xy[i][1];
			++imos[xy[i][0]];
			--imos[xy[i][1]+1];
		}
	}
	foreach (i; 0..N)
	{
		imos[i+1] += imos[i];
	}
	
	auto B = new long[](N);
	foreach (i; 0..N)
	{
		B[i] = A[i] * imos[i];
	}

	auto st = new SegTree!(long, long)(cast(int)N, (long a, long b) => a+b, (long a, long b) => a+b, 0, 0);
	foreach_reverse (i; 0..Q)
	{
		if (c[i][0] == 'B')
		{
			st.update(xy[i][0], xy[i][1]+1, 1);
		}
		else
		{
			auto pos = xy[i][0];
			B[pos] += xy[i][1] * st.query(pos);
		}
	}

	B.map!(to!string).join(" ").writeln;
	stdout.flush;
	debug readln;
}
0