結果

問題 No.789 範囲の合計
ユーザー heno239heno239
提出日時 2019-03-14 16:18:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 258 ms / 1,000 ms
コード長 2,179 bytes
コンパイル時間 1,359 ms
コンパイル使用メモリ 128,648 KB
実行使用メモリ 16,728 KB
最終ジャッジ日時 2023-09-09 03:16:56
合計ジャッジ時間 5,257 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 218 ms
15,672 KB
testcase_03 AC 76 ms
5,244 KB
testcase_04 AC 215 ms
15,628 KB
testcase_05 AC 178 ms
15,932 KB
testcase_06 AC 185 ms
15,792 KB
testcase_07 AC 65 ms
5,384 KB
testcase_08 AC 133 ms
9,940 KB
testcase_09 AC 124 ms
8,668 KB
testcase_10 AC 258 ms
16,728 KB
testcase_11 AC 192 ms
15,548 KB
testcase_12 AC 194 ms
15,592 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ld INF = (ld)10000000000000;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

struct SegT {
private:
	int sz; vector<ll> node;
	const ll init_c = 0;
public:
	SegT(int n) {
		sz = 1;
		while (sz < n)sz *= 2;
		node.resize(2 * sz - 1, init_c);
	}
	ll f(ll a, ll b) {
		return a + b;
	}
	void add(int k, ll a) {
		k += sz - 1;
		node[k] += a;
		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}
	ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = sz;
		if (r <= a || b <= l)return init_c;
		else if (a <= l && r <= b)return node[k];
		else {
			ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return f(vl, vr);
		}
	}
};

map<int, int> mp;
int n;
struct query {
	int t, l, r;
};
int main() {
	cin >> n;
	vector<query> q(n);
	vector<int> v;
	rep(i, n) {
		cin >> q[i].t >> q[i].l >> q[i].r;
		v.push_back(q[i].l);
		if(q[i].t==1)v.push_back(q[i].r);
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	rep(i, v.size()) {
		mp[v[i]] = i;
	}
	SegT st(v.size());
	ll ans = 0;
	rep(i, n) {
		if (q[i].t == 0) {
			q[i].l = mp[q[i].l];
			st.add(q[i].l, q[i].r);
		}
		else {
			q[i].l = mp[q[i].l];
			q[i].r = mp[q[i].r];
			ans += st.query(q[i].l, q[i].r + 1);
		}
	}
	cout << ans << endl;
	//stop
	return 0;
}
0