結果

問題 No.877 Range ReLU Query
ユーザー pockynypockyny
提出日時 2019-09-06 22:22:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 317 ms / 2,000 ms
コード長 1,208 bytes
コンパイル時間 1,160 ms
コンパイル使用メモリ 86,792 KB
実行使用メモリ 12,188 KB
最終ジャッジ日時 2024-04-25 22:03:06
合計ジャッジ時間 5,621 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,760 KB
testcase_01 AC 4 ms
6,944 KB
testcase_02 AC 4 ms
6,940 KB
testcase_03 AC 5 ms
6,944 KB
testcase_04 AC 3 ms
9,808 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 4 ms
9,804 KB
testcase_07 AC 3 ms
7,756 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 313 ms
11,556 KB
testcase_12 AC 274 ms
11,344 KB
testcase_13 AC 222 ms
10,828 KB
testcase_14 AC 240 ms
10,692 KB
testcase_15 AC 317 ms
12,188 KB
testcase_16 AC 304 ms
12,088 KB
testcase_17 AC 310 ms
11,924 KB
testcase_18 AC 306 ms
11,924 KB
testcase_19 AC 310 ms
12,104 KB
testcase_20 AC 312 ms
12,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
using ll = long long;
ll n,mx = 100000000000000;
pair<ll,ll> t[200010];
pair<ll,ll> add(pair<ll,ll> p, pair<ll,ll> q){
	p.first += q.first;
	p.second += q.second;
	return p;
}
void update(ll p,ll a){
	for(t[p += n] = {a,1};p>1;p >>= 1){
		t[p>>1] = add(t[p],t[p^1]);
	}
}

pair<ll,ll> query(ll l, ll r){
	pair<ll,ll> mn = {0LL,0LL};
	for(l += n, r += n; l<r; l >>= 1,r >>= 1){
		if(l&1) mn = add(mn,t[l++]);
		if(r&1) mn = add(mn,t[--r]);
	}
	return mn;
}

pair<ll,ll> p[100010];
pair<ll,pair<ll,pair<ll,ll>>> qu[100010];
ll ans[100010];
int main(){
	int i,q;
	cin >> n >> q;
	for(i=0;i<n;i++){
		ll x; cin >> x;
		p[i] = {x,i};
	}
	for(i=0;i<q;i++){
		ll b,x,l,r;
		cin >> b >> l >> r >> x;
		l--;
		qu[i] = {x,{i,{l,r}}};
	}
	sort(p,p + n); sort(qu,qu + q);
	int j = n - 1;
	for(i=q - 1;i>=0;i--){
		ll val = qu[i].first,ind = qu[i].second.first,l = qu[i].second.second.first,r = qu[i].second.second.second;
		while(j>=0 && p[j].first>val){
			update(p[j].second,p[j].first);
			j--;
		}
		pair<ll,ll> z = query(l,r);
		ans[ind] = z.first - z.second*val;
	}
	for(i=0;i<q;i++){
		cout << ans[i] << endl;
	}
}
0