結果

問題 No.789 範囲の合計
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-03-20 08:26:27
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,009 bytes
コンパイル時間 1,050 ms
コンパイル使用メモリ 66,692 KB
実行使用メモリ 65,896 KB
最終ジャッジ日時 2023-09-07 11:56:29
合計ジャッジ時間 11,016 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 TLE -
testcase_03 AC 213 ms
4,376 KB
testcase_04 TLE -
testcase_05 AC 769 ms
51,656 KB
testcase_06 AC 781 ms
54,024 KB
testcase_07 AC 120 ms
4,376 KB
testcase_08 AC 792 ms
65,896 KB
testcase_09 AC 726 ms
60,128 KB
testcase_10 TLE -
testcase_11 AC 445 ms
53,036 KB
testcase_12 AC 488 ms
52,924 KB
testcase_13 AC 1 ms
4,388 KB
testcase_14 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
using namespace std;

struct E{
	int l,r;
	bool operator<(const E& e1)const {
		if(l!=e1.l)return l<e1.l;
		return r<e1.r;
	}
};
std::map<E,int> ms;
void f(int x,int l,int r,int y){
	if((l<=x && x<=r)==false){
		return ;
	}
	E e1;
	e1.l=l;
	e1.r=r;
	if(l==r){
		ms[e1]+=y;
	}else if(l<=x && x<=r){
		ms[e1]+=y;
		int m=(l+r)/2;
		f(x,l,m,y);
		f(x,m+1,r,y);
	}
}
long long int sum(int l,int r,int l2,int r2){
	E e1;
	e1.l=l;
	e1.r=r;
	if (ms.find(e1)==ms.end()){
		return 0;
	}else{
		if(r<l2){
			return 0;
		}
		if(r2<l){
			return 0;
		}
		if (l2<=l&&r<=r2){
			return ms[e1];
		}
		
		int m=(l+r)/2;
		long long int res=0;
		res=sum(l,m,l2,r2);
		res+=sum(m+1,r,l2,r2);
		return res;
	}
}


int main() {
	// your code goes here
	int x,n;
	cin>>n;
	long long int ans=0;
	for(int i=0;i<n;i++){
		cin>>x;
		if(x==0){
			int p1,y;
			cin>>p1>>y;
			f(p1,0,1073741823,y);
		}else{
			int l,r;
			cin>>l>>r;
			ans+=sum(0,1073741823,l,r);
		}
	}
	cout<<ans<<"\n";
	return 0;
}
0