結果

問題 No.789 範囲の合計
ユーザー aa
提出日時 2019-02-23 07:04:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,092 bytes
コンパイル時間 1,509 ms
コンパイル使用メモリ 172,824 KB
実行使用メモリ 5,788 KB
最終ジャッジ日時 2023-08-18 14:36:16
合計ジャッジ時間 4,173 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

template<typename T>
struct BIT
{
	int N, K;
	vector<T> bit;

	BIT (int X)
	{
		bit = vector<T>(X+1, 0);
		N = X+1;
	}

	void add(int idx, T w)
	{
		for (int x = idx; x <= N; x += x&-x)
		{
			bit[x] += w;
		}
	}

	T sum(int idx)
	{
		T res = 0;
		for (int x = idx; x > 0; x -= x&-x) res += bit[x];
		return res;
	}
};

void solve()
{
	int N;
	cin >> N;
	vector<int> as(N), bs(N), qs(N), comp;
	for (int i = 0; i < N; i++)
	{
		cin >> qs[i] >> as[i] >> bs[i];
		comp.push_back(as[i]);
		if (qs[i]) comp.push_back(bs[i]);
	}
	sort(comp.begin(), comp.end());
	comp.erase(unique(comp.begin(), comp.end()), comp.end());
	BIT<int> bit(comp.size()+1);
	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		int ax = lower_bound(comp.begin(), comp.end(), as[i]) - comp.begin();
		if (qs[i])
		{
			int bx = lower_bound(comp.begin(), comp.end(), bs[i]) - comp.begin() + 1;
			ans += bit.sum(bx) - bit.sum(ax);
		}
		else
		{
			bit.add(ax+1, bs[i]);
		}
	}
	cout << ans << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}
0