結果

問題 No.789 範囲の合計
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-03-17 18:57:50
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 972 bytes
コンパイル時間 563 ms
コンパイル使用メモリ 66,848 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-07 11:54:22
合計ジャッジ時間 2,980 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
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 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

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){
	if((l<=x && x<=r)==false){
		return ;
	}
	E e1;
	e1.l=l;
	e1.r=r;
	if(l==r){
		ms[e1]+=1;
	}else if(l<=x && x<=r){
		ms[e1]+=1;
		int m=(l+r)/2;
		f(x,l,m);
		f(x,m+1,r);
	}
}
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;
		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;
			cin>>p1;
			f(p1,0,1073741823);
		}else{
			int l,r;
			cin>>l>>r;
			ans+=sum(0,1073741823,l,r);
		}
	}
	cout<<ans<<"\n";
	return 0;
}
0