結果

問題 No.789 範囲の合計
ユーザー hornistyfhornistyf
提出日時 2020-01-08 22:07:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 298 ms / 1,000 ms
コード長 1,389 bytes
コンパイル時間 1,351 ms
コンパイル使用メモリ 103,748 KB
実行使用メモリ 23,604 KB
最終ジャッジ日時 2023-08-15 00:47:34
合計ジャッジ時間 4,494 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 259 ms
22,408 KB
testcase_03 AC 82 ms
7,284 KB
testcase_04 AC 251 ms
21,764 KB
testcase_05 AC 198 ms
22,748 KB
testcase_06 AC 214 ms
22,600 KB
testcase_07 AC 74 ms
7,172 KB
testcase_08 AC 155 ms
15,240 KB
testcase_09 AC 143 ms
11,768 KB
testcase_10 AC 298 ms
23,604 KB
testcase_11 AC 224 ms
22,140 KB
testcase_12 AC 220 ms
21,836 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//yuki789.cpp
//Wed Jan  8 20:11:42 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

ll nodenum,seg[800000];

void init(ll n){
	nodenum = 1;
	while (nodenum<n){
		nodenum*=2;
	}
	fill(seg,seg+nodenum*2-1,0);
}

void add(ll index, ll x){
	index += nodenum-1;
	seg[index] += x;
	while (index>0){
		index = (index-1)/2;
		seg[index] = seg[index*2+1]+seg[index*2+2];
	}
}

ll query(ll a, ll b, ll k, ll l, ll r){
	if (b<=l || r<=a){
		return 0;
	}
	if (a<=l && r<=b){
		return seg[k];
	}else {
		ll v1 = query(a,b,k*2+1,l,(l+r)/2);
		ll v2 = query(a,b,k*2+2,(l+r)/2,r);
		return v1+v2;
	}
}

int main(){
	ll n;
	cin >> n;

	ll q[n],x[n],y[n];
	vector<ll> pos;
	for (int i=0;i<n;i++){
		cin >> q[i] >> x[i] >> y[i];
		pos.push_back(x[i]);
		pos.push_back(y[i]);
	}

	sort(pos.begin(),pos.end());
	pos.erase(unique(pos.begin(),pos.end()),pos.end());

	map<ll,ll> mpfor;
	for (ll i=0;i<pos.size();i++){
		mpfor[pos[i]] = i;
	}

	init(pos.size());

	ll ans = 0;
	for (int i=0;i<n;i++){
		if (q[i]){
			ans += query(mpfor[x[i]],mpfor[y[i]]+1,0,0,nodenum);
		}else{
			add(mpfor[x[i]],y[i]);
		}
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}
0