結果

問題 No.877 Range ReLU Query
ユーザー chocoruskchocorusk
提出日時 2019-09-06 22:27:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 597 ms / 2,000 ms
コード長 1,680 bytes
コンパイル時間 999 ms
コンパイル使用メモリ 107,824 KB
実行使用メモリ 46,648 KB
最終ジャッジ日時 2023-08-08 04:20:54
合計ジャッジ時間 7,888 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
15,588 KB
testcase_01 AC 8 ms
15,900 KB
testcase_02 AC 7 ms
15,864 KB
testcase_03 AC 9 ms
15,696 KB
testcase_04 AC 7 ms
15,788 KB
testcase_05 AC 7 ms
15,600 KB
testcase_06 AC 8 ms
15,724 KB
testcase_07 AC 8 ms
15,712 KB
testcase_08 AC 9 ms
15,820 KB
testcase_09 AC 7 ms
15,792 KB
testcase_10 AC 8 ms
15,708 KB
testcase_11 AC 553 ms
40,532 KB
testcase_12 AC 491 ms
39,892 KB
testcase_13 AC 376 ms
33,824 KB
testcase_14 AC 393 ms
32,144 KB
testcase_15 AC 588 ms
45,884 KB
testcase_16 AC 580 ms
45,228 KB
testcase_17 AC 597 ms
45,912 KB
testcase_18 AC 591 ms
46,220 KB
testcase_19 AC 429 ms
46,648 KB
testcase_20 AC 551 ms
46,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int sz;
vector<int> seg[1<<18];
vector<ll> sum[1<<18];
int a[1<<17];
ll query(int a, int b, int x){
	a+=sz, b+=sz;
	ll ret=0;
	for(; a<b; a>>=1, b>>=1){
		if(b&1){
			b--;
          //cout<<b<<endl;
          if(!seg[b].empty()){
			int k=lower_bound(seg[b].begin(), seg[b].end(), x)-seg[b].begin();
			ret+=sum[b].back()-sum[b][k]-((ll)seg[b].size()-k)*x;
          }
		}
		if(a&1){
          //cout<<a<<endl;
          if(!seg[a].empty()){
			int k=lower_bound(seg[a].begin(), seg[a].end(), x)-seg[a].begin();
			ret+=sum[a].back()-sum[a][k]-((ll)seg[a].size()-k)*x;
          }
			a++;
		}
	}
	return ret;
}
int main()
{
	int n, q; cin>>n>>q;
	for(int i=0; i<n; i++) cin>>a[i];
	sz=1;
	while(sz<n) sz<<=1;
	for(int i=0; i<n; i++){
		seg[i+sz].push_back(a[i]);
		sum[i+sz].push_back(0);
		sum[i+sz].push_back(a[i]);
	}
	for(int i=sz-1; i>=1; i--){
		for(auto x:seg[2*i]) seg[i].push_back(x);
		for(auto x:seg[2*i+1]) seg[i].push_back(x);
		sort(seg[i].begin(), seg[i].end());
		sum[i].resize(seg[i].size()+1);
		for(int j=0; j<seg[i].size(); j++) sum[i][j+1]=sum[i][j]+seg[i][j];
	}
	for(int i=0; i<q; i++){
		int t, l, r, x; cin>>t>>l>>r>>x;
		cout<<query(l-1, r, x)<<endl;
	}
	return 0;
}
0