結果

問題 No.789 範囲の合計
ユーザー okok
提出日時 2019-02-22 11:43:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 78 ms / 1,000 ms
コード長 1,402 bytes
コンパイル時間 2,028 ms
コンパイル使用メモリ 79,972 KB
実行使用メモリ 8,004 KB
最終ジャッジ日時 2023-08-15 19:08:50
合計ジャッジ時間 3,726 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 72 ms
7,648 KB
testcase_03 AC 44 ms
7,420 KB
testcase_04 AC 68 ms
7,660 KB
testcase_05 AC 58 ms
7,812 KB
testcase_06 AC 61 ms
7,668 KB
testcase_07 AC 36 ms
7,424 KB
testcase_08 AC 50 ms
7,712 KB
testcase_09 AC 47 ms
7,720 KB
testcase_10 AC 78 ms
8,004 KB
testcase_11 AC 63 ms
7,668 KB
testcase_12 AC 63 ms
7,660 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define EPS (1e-5)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

vector<int> bit;

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

void add(int i,int x){
	while(i <= bit.size()){
		bit[i] += x;
		i += i & -i;
	}
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int n, ans = 0;
	vector<int> s, a, b, hoge;
	
	cin>>n;
	
	s.resize(n);
	a.resize(n);
	b.resize(n);
	
	for(int i = 0; i < n; i++){
		cin>>s[i]>>a[i]>>b[i];
		
		if(s[i]){
			hoge.push_back(a[i]);
			hoge.push_back(b[i]);
		} else {
			hoge.push_back(a[i]);
		}
	}
	
	sort(hoge.begin(),hoge.end());
	
	hoge.erase(unique(hoge.begin(),hoge.end()),hoge.end());
	
	bit.resize(hoge.size()+1);
	
	for(int i = 0; i < n; i++){
		if(s[i]){
			int tempa = lower_bound(hoge.begin(),hoge.end(),a[i]) - hoge.begin()+1;
			int tempb = lower_bound(hoge.begin(),hoge.end(),b[i]) - hoge.begin()+1;
			ans += sum(tempb)-sum(tempa-1);
		} else {
			int temp = lower_bound(hoge.begin(),hoge.end(),a[i]) - hoge.begin()+1;
			
			add(temp,b[i]);
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}
0