結果

問題 No.789 範囲の合計
ユーザー kotatsugamekotatsugame
提出日時 2019-02-08 23:01:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 943 bytes
コンパイル時間 994 ms
コンパイル使用メモリ 91,876 KB
実行使用メモリ 13,720 KB
最終ジャッジ日時 2023-09-14 03:54:45
合計ジャッジ時間 3,530 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:26:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   26 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
//1-indexed
#include<vector>
template<typename T>
struct BIT{
	int n;
	vector<T>bit;
	BIT(int n_=0,T a=0):n(n_),bit(n_+1,a){}
	T sum(int i)
	{
		T ans=0;
		for(;i>0;i-=i&-i)ans+=bit[i];
		return ans;
	}
	void add(int i,T a)
	{
		if(i==0)return;
		for(;i<=n;i+=i&-i)bit[i]+=a;
	}
};
int n;
main()
{
	cin>>n;
	vector<pair<int,pair<int,int> > >a;
	vector<int>id;
	for(int i=0;i<n;i++)
	{
		int u,v,w;cin>>u>>v>>w;
		a.push_back(make_pair(u,make_pair(v,w)));
		id.push_back(v);
		id.push_back(w);
	}
	map<int,int>M;
	int sz=0;
	sort(id.begin(),id.end());
	for(int i=0;i<id.size();i++)
	{
		if(!M[id[i]])M[id[i]]=++sz;
	}
	BIT<int>P(sz);
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(a[i].first)
		{
			ans+=P.sum(M[a[i].second.second])-P.sum(M[a[i].second.first]-1);
		}
		else
		{
			P.add(M[a[i].second.first],a[i].second.second);
		}
	}
	cout<<ans<<endl;
}
0