結果

問題 No.789 範囲の合計
ユーザー chocoruskchocorusk
提出日時 2019-02-08 22:16:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 326 ms / 1,000 ms
コード長 1,010 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 101,176 KB
実行使用メモリ 17,044 KB
最終ジャッジ日時 2023-09-14 03:44:14
合計ジャッジ時間 4,067 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 293 ms
15,704 KB
testcase_03 AC 73 ms
5,360 KB
testcase_04 AC 278 ms
15,172 KB
testcase_05 AC 185 ms
15,840 KB
testcase_06 AC 214 ms
15,704 KB
testcase_07 AC 64 ms
5,428 KB
testcase_08 AC 149 ms
9,988 KB
testcase_09 AC 136 ms
9,564 KB
testcase_10 AC 326 ms
17,044 KB
testcase_11 AC 225 ms
14,764 KB
testcase_12 AC 225 ms
14,712 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;
int m;
ll bit[300002];
 
ll sum(int i){
	ll s=0;
	while(i>0){
		s+=bit[i];
		i-=(i&(-i));
	}
	return s;
}
 
void add(int i, ll x){
	while(i<=m){
		bit[i]+=x;
		i+=(i&(-i));
	}
}
int main()
{
	int n;
	cin>>n;
	int t[100001]; ll x[100001], y[100001];
	map<ll, int> mp;
	for(int i=0; i<n; i++){
		cin>>t[i]>>x[i]>>y[i];
		mp[x[i]]=0;
		if(t[i]==1) mp[y[i]]=0;
	}
	m=1;
	for(auto& p:mp){
		p.second=m;
		m++;
	}
	for(int i=0; i<n; i++){
		x[i]=mp[x[i]];
		if(t[i]==1) y[i]=mp[y[i]];
	}
	ll ans=0;
	for(int i=0; i<n; i++){
		if(t[i]==0) add(x[i], y[i]);
		else ans+=(sum(y[i])-sum(x[i]-1));
	}
	cout<<ans<<endl;
	return 0;
}
0