結果

問題 No.877 Range ReLU Query
ユーザー autumn-eelautumn-eel
提出日時 2019-09-06 22:21:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,871 bytes
コンパイル時間 2,013 ms
コンパイル使用メモリ 174,844 KB
実行使用メモリ 18,244 KB
最終ジャッジ日時 2024-04-25 22:02:45
合計ジャッジ時間 5,480 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
14,548 KB
testcase_01 AC 7 ms
12,032 KB
testcase_02 AC 6 ms
12,032 KB
testcase_03 AC 7 ms
12,032 KB
testcase_04 AC 7 ms
11,904 KB
testcase_05 AC 6 ms
11,904 KB
testcase_06 AC 6 ms
12,032 KB
testcase_07 AC 7 ms
11,904 KB
testcase_08 AC 6 ms
12,032 KB
testcase_09 AC 7 ms
12,032 KB
testcase_10 AC 7 ms
11,904 KB
testcase_11 AC 202 ms
14,976 KB
testcase_12 AC 164 ms
17,456 KB
testcase_13 AC 130 ms
18,244 KB
testcase_14 AC 138 ms
17,264 KB
testcase_15 AC 198 ms
17,372 KB
testcase_16 AC 185 ms
17,440 KB
testcase_17 AC 198 ms
17,892 KB
testcase_18 AC 195 ms
17,308 KB
testcase_19 AC 128 ms
17,836 KB
testcase_20 AC 173 ms
17,560 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