結果

問題 No.2065 Sum of Min
ユーザー okkuukenkenokkuukenken
提出日時 2022-09-02 21:59:51
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 592 ms / 2,000 ms
コード長 1,545 bytes
コンパイル時間 1,954 ms
コンパイル使用メモリ 163,148 KB
実行使用メモリ 56,340 KB
最終ジャッジ日時 2024-04-27 21:32:11
合計ジャッジ時間 12,559 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 339 ms
56,196 KB
testcase_05 AC 322 ms
56,256 KB
testcase_06 AC 425 ms
56,224 KB
testcase_07 AC 337 ms
56,184 KB
testcase_08 AC 485 ms
56,292 KB
testcase_09 AC 374 ms
56,240 KB
testcase_10 AC 399 ms
56,284 KB
testcase_11 AC 394 ms
56,340 KB
testcase_12 AC 557 ms
56,172 KB
testcase_13 AC 555 ms
56,276 KB
testcase_14 AC 558 ms
56,248 KB
testcase_15 AC 556 ms
56,240 KB
testcase_16 AC 554 ms
56,264 KB
testcase_17 AC 583 ms
56,216 KB
testcase_18 AC 572 ms
56,196 KB
testcase_19 AC 592 ms
56,336 KB
testcase_20 AC 566 ms
56,232 KB
testcase_21 AC 561 ms
56,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<random>
#include<bitset>
#include<cassert>
#include<complex>
#include<fstream>
#include<cstdlib>
#include<functional>
#include<array>
using namespace std;
typedef long long ll;
const int mod=998244353;
class RMQ{
	int n;
	vector<int>vec;
	vector<vector<int>>dat;
	vector<vector<ll>>sum;
public:
	void init(int k,int l,int r){
		if(r-l==1)
			dat[k].push_back(vec[k-(n-1)]);
		else{
			init(k*2+1,l,(l+r)/2);
			init(k*2+2,(l+r)/2,r);
			merge(dat[k*2+1].begin(),dat[k*2+1].end(),dat[k*2+2].begin(),dat[k*2+2].end(),back_inserter(dat[k]));
		}
		sum[k].resize(dat[k].size()+1);
		for(int i=0;i<dat[k].size();i++)
			sum[k][i+1]=sum[k][i]+dat[k][i];
	}
	RMQ(vector<int>a):n(1),vec(a){
		while(n<a.size())
			n*=2;
		vec.resize(n);
		dat.resize(2*n-1);
		sum.resize(2*n-1);
		init(0,0,n);
	}
	ll query(int a,int b,int x,int k=0,int l=0,int r=-1){
		if(r==-1)
			r=n;
		if(r<=a||b<=l)
			return 0;
		if(a<=l&&r<=b){
			int itr=lower_bound(dat[k].begin(),dat[k].end(),x)-dat[k].begin();
			return sum[k][itr]+ll(dat[k].size()-itr)*x;
		}
		ll vl=query(a,b,x,k*2+1,l,(l+r)/2);
		ll vr=query(a,b,x,k*2+2,(l+r)/2,r);
		return vl+vr;
	}
};
int main(){
	static int n,q,a[100000],l,r,x;
	cin>>n>>q;
	for(int i=0;i<n;i++)
		cin>>a[i];
	RMQ seg(vector<int>(a,a+n));
	while(cin>>l>>r>>x)
		cout<<seg.query(--l,r,x)<<endl;
}
0