結果

問題 No.789 範囲の合計
ユーザー azbrugbyazbrugby
提出日時 2019-02-23 15:57:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 128 ms / 1,000 ms
コード長 1,802 bytes
コンパイル時間 707 ms
コンパイル使用メモリ 77,924 KB
実行使用メモリ 8,708 KB
最終ジャッジ日時 2023-08-20 05:47:16
合計ジャッジ時間 3,636 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,344 KB
testcase_01 AC 2 ms
5,436 KB
testcase_02 AC 121 ms
8,356 KB
testcase_03 AC 84 ms
8,708 KB
testcase_04 AC 118 ms
8,308 KB
testcase_05 AC 109 ms
8,420 KB
testcase_06 AC 111 ms
8,456 KB
testcase_07 AC 70 ms
8,512 KB
testcase_08 AC 94 ms
8,296 KB
testcase_09 AC 93 ms
8,364 KB
testcase_10 AC 128 ms
8,512 KB
testcase_11 AC 113 ms
8,432 KB
testcase_12 AC 112 ms
8,300 KB
testcase_13 AC 2 ms
5,392 KB
testcase_14 AC 2 ms
5,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <cstdio>
#include <cmath>
#define mk make_pair
#define pb push_back
#define printf printf_s
#define scanf scanf_s
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pos;
const ll MOD = 1000000007, N = 100010, dx[4] = { -1,1,0,0 }, dy[4] = { 0,0,-1,1 }, MIN = -72340172838076673, MAX = 72340172838076673;

ll mn(ll a, ll b) {
	if (a == -1)return b;
	if (b == -1)return a;
	return min(a, b);
}
ll gcd(ll v1, ll v2) {
	if (v1 == 0)return v2; if (v2 == 0)return v1; if (v2 > v1)return gcd(v2%v1, v1); return gcd(v1%v2, v2);
}

ll pw(ll v1, ll v2) {
	ll v3 = 1;
	while (v2 > 0) {
		if (v2 % 2)v3 = (v3*v1) % MOD;
		v1 = (v1*v1) % MOD;
		v2 /= 2;
	}
	return v3;
}

struct ab {
	ll a, b;
	bool operator<(const ab& right) const {
		return right.b*a - right.a*b < 0;
	}
};

pair<ll, pos> e[N];
ll n,bt[N*2],vv[N*2];

ll fi(ll v1) {
	return upper_bound(vv + 1, vv + 2 * n + 1, v1) - vv - 1;
}

void ad(ll v1, ll v2) {
	while (v1 <= n*2) {
		bt[v1] += v2;
		v1 += v1 & -v1;
	}
}

ll sm(ll v1) {
	ll v2 = 0;
	while (v1 > 0) {
		v2 += bt[v1];
		v1 -= v1 & -v1;
	}
	return v2;
}

ll ans = 0;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> e[i].first >> e[i].second.first >> e[i].second.second;
		e[i].second.first++;
		if(e[i].first==1)e[i].second.second++;
		vv[i * 2 - 1] = e[i].second.first;
		vv[i * 2] = e[i].second.second;
	}
	sort(vv + 1, vv + 2 * n + 1);
	for (int i = 1; i <= n; i++) {
		if (e[i].first == 0) {
			ad(fi(e[i].second.first), e[i].second.second);
		}
		else {
			ll v1 = sm(fi(e[i].second.second)) - sm(fi(e[i].second.first - 1));
			ans += v1;
		}
	}
	cout << ans << endl;
	return 0;
}
0