結果

問題 No.877 Range ReLU Query
ユーザー chocoruskchocorusk
提出日時 2019-09-06 22:27:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 596 ms / 2,000 ms
コード長 1,680 bytes
コンパイル時間 1,208 ms
コンパイル使用メモリ 111,044 KB
実行使用メモリ 46,948 KB
最終ジャッジ日時 2024-04-25 22:03:41
合計ジャッジ時間 8,127 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
15,816 KB
testcase_01 AC 8 ms
15,816 KB
testcase_02 AC 7 ms
15,944 KB
testcase_03 AC 9 ms
15,816 KB
testcase_04 AC 6 ms
15,816 KB
testcase_05 AC 8 ms
15,684 KB
testcase_06 AC 8 ms
15,812 KB
testcase_07 AC 7 ms
15,816 KB
testcase_08 AC 9 ms
15,944 KB
testcase_09 AC 7 ms
15,812 KB
testcase_10 AC 8 ms
15,816 KB
testcase_11 AC 560 ms
40,740 KB
testcase_12 AC 485 ms
39,952 KB
testcase_13 AC 383 ms
33,864 KB
testcase_14 AC 393 ms
32,328 KB
testcase_15 AC 580 ms
46,232 KB
testcase_16 AC 572 ms
45,528 KB
testcase_17 AC 596 ms
45,980 KB
testcase_18 AC 592 ms
46,240 KB
testcase_19 AC 423 ms
46,824 KB
testcase_20 AC 543 ms
46,948 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