結果

問題 No.877 Range ReLU Query
ユーザー autumn-eelautumn-eel
提出日時 2019-09-06 22:21:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 1,871 bytes
コンパイル時間 2,070 ms
コンパイル使用メモリ 176,036 KB
実行使用メモリ 17,244 KB
最終ジャッジ日時 2023-08-08 04:20:11
合計ジャッジ時間 5,662 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
14,012 KB
testcase_01 AC 5 ms
13,996 KB
testcase_02 AC 5 ms
13,924 KB
testcase_03 AC 5 ms
13,876 KB
testcase_04 AC 4 ms
14,020 KB
testcase_05 AC 5 ms
13,828 KB
testcase_06 AC 5 ms
13,980 KB
testcase_07 AC 4 ms
13,812 KB
testcase_08 AC 6 ms
13,932 KB
testcase_09 AC 5 ms
13,884 KB
testcase_10 AC 5 ms
13,908 KB
testcase_11 AC 183 ms
17,112 KB
testcase_12 AC 160 ms
17,000 KB
testcase_13 AC 127 ms
16,956 KB
testcase_14 AC 134 ms
17,140 KB
testcase_15 AC 189 ms
17,176 KB
testcase_16 AC 180 ms
17,244 KB
testcase_17 AC 186 ms
17,084 KB
testcase_18 AC 183 ms
17,084 KB
testcase_19 AC 128 ms
17,064 KB
testcase_20 AC 174 ms
17,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

#define N (1<<18)
template<class T>
struct RMQ{
	pair<T,int>dat[2*N];
	T inf;
	function<pair<T,int>(pair<T,int>,pair<T,int>)>merge;
	RMQ(T Inf,function<pair<T,int>(pair<T,int>,pair<T,int>)>Merge){
		inf=Inf;merge=Merge;
		rep(i,2*N-1){
			dat[i].first=inf;
			dat[i].second=0;
		}
	}
	void update(int k,pair<T,int> x){
		k+=N-1;
		dat[k]=x;
		while(k){
			k=(k-1)/2;
			dat[k]=merge(dat[k*2+1],dat[k*2+2]);
		}
	}
	pair<T,int>query(int a,int b,int k=0,int l=0,int r=N){
		if(b<=l||r<=a)return make_pair(inf,0);
		if(a<=l&&r<=b)return dat[k];
		auto lb=query(a,b,k*2+1,l,(l+r)/2);
		auto rb=query(a,b,k*2+2,(l+r)/2,r);
		return merge(lb,rb);
	}
	T getValue(int a,int b){
		return query(a,b).first;
	}
	int getIndex(int a,int b){
		return query(a,b).second;
	}
};
template<class T>
pair<T,int>RangeMax(pair<T,int>a,pair<T,int>b){
	return a.first>=b.first?a:b;
}
template<class T>
pair<T,int>RangeMin(pair<T,int>a,pair<T,int>b){
	return a.first<=b.first?a:b;
}
template<class T>
pair<T,int>RangeSum(pair<T,int>a,pair<T,int>b){
	return {a.first+b.first,a.second+b.second};
}
RMQ<ll>seg(0,RangeSum<ll>);
P a[200000];
struct st{
	int l,r,x,id;
}q[200000];

ll ans[200000];
int main(){
	int n,Q;cin>>n>>Q;
	rep(i,n){
		scanf("%d",&a[i].first);
		a[i].second=i;
	}
	rep(i,Q){
		scanf("%*d%d%d%d",&q[i].l,&q[i].r,&q[i].x);q[i].l--;
		q[i].id=i;
	}
	sort(a,a+n,greater<>());
	sort(q,q+Q,[](st a,st b){return a.x>b.x;});
	int s=0;
	rep(i,Q){
		while(a[s].first>=q[i].x){
			seg.update(a[s].second,make_pair(a[s].first,1));
			s++;
		}
		ans[q[i].id]=seg.getValue(q[i].l,q[i].r)-seg.getIndex(q[i].l,q[i].r)*(ll)q[i].x;
	}
	rep(i,Q){
		printf("%lld\n",ans[i]);
	}
}
0