結果

問題 No.789 範囲の合計
ユーザー 👑 jupirojupiro
提出日時 2020-01-27 18:55:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 202 ms / 1,000 ms
コード長 2,027 bytes
コンパイル時間 1,231 ms
コンパイル使用メモリ 125,384 KB
実行使用メモリ 19,688 KB
最終ジャッジ日時 2023-10-12 13:03:51
合計ジャッジ時間 4,200 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 180 ms
18,712 KB
testcase_03 AC 46 ms
10,028 KB
testcase_04 AC 166 ms
18,348 KB
testcase_05 AC 117 ms
18,648 KB
testcase_06 AC 134 ms
18,948 KB
testcase_07 AC 38 ms
10,016 KB
testcase_08 AC 86 ms
13,532 KB
testcase_09 AC 78 ms
13,980 KB
testcase_10 AC 202 ms
19,688 KB
testcase_11 AC 141 ms
18,088 KB
testcase_12 AC 138 ms
18,068 KB
testcase_13 AC 2 ms
4,372 KB
testcase_14 AC 1 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct query {
	query(ll _q, ll _x, ll _y) :q(_q), x(_x), y(_y) {};
	ll q, x, y;
};

class BIT {
private:
	ll N;
	vector<ll> node;
public:
	BIT(ll M) {
		node = vector<ll>(M + 1, 0);
		N = M;
	}

	ll sum(ll i) {
		ll s = 0;
		while (i > 0) {
			s += node[i];
			i -= i & -i;
		}
		return s;
	}

	ll sum(ll i, ll j) {
		ll l = sum(i - 1);
		ll r = sum(j);
		return r - l;
	}

	void add(ll i, ll x) {
		while (i <= N) {
			node[i] += x;
			i += i & -i;
		}
	}
};


int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	ll n; scanf("%lld", &n);
	map<ll, ll> mp;
	vector<query> vq;
	BIT bit(n * 5);
	for (ll i = 0; i < n; i++) {
		ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c);
		if (a == 0) mp[b] = 0;
		else mp[b] = 0, mp[c] = 0;
		vq.emplace_back(a, b, c);
	}
	{
		ll idx = 1;
		for (auto itr = mp.begin(); itr != mp.end(); itr++) itr->second = idx++;
		for (ll i = 0; i < vq.size(); i++) {
			if (vq[i].q == 0) vq[i].x = mp[vq[i].x];
			else vq[i].x = mp[vq[i].x], vq[i].y = mp[vq[i].y];
		}
	}
	ll res = 0;
	for (ll i = 0; i < n; i++) {
		if (vq[i].q == 0) bit.add(vq[i].x, vq[i].y);
		else res += bit.sum(vq[i].x, vq[i].y);
	}
	cout << res << endl;
	return 0;
}
0