結果

問題 No.2065 Sum of Min
ユーザー 沙耶花沙耶花
提出日時 2022-09-02 21:34:05
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 1,190 bytes
コンパイル時間 4,660 ms
コンパイル使用メモリ 267,248 KB
実行使用メモリ 15,568 KB
最終ジャッジ日時 2023-08-10 03:28:33
合計ジャッジ時間 9,669 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 99 ms
13,472 KB
testcase_05 AC 93 ms
11,960 KB
testcase_06 AC 76 ms
11,636 KB
testcase_07 AC 63 ms
10,204 KB
testcase_08 AC 96 ms
12,016 KB
testcase_09 AC 174 ms
15,568 KB
testcase_10 AC 121 ms
13,496 KB
testcase_11 AC 118 ms
13,336 KB
testcase_12 AC 191 ms
15,392 KB
testcase_13 AC 186 ms
15,248 KB
testcase_14 AC 184 ms
15,532 KB
testcase_15 AC 184 ms
15,388 KB
testcase_16 AC 181 ms
15,260 KB
testcase_17 AC 182 ms
15,408 KB
testcase_18 AC 188 ms
15,332 KB
testcase_19 AC 187 ms
15,488 KB
testcase_20 AC 192 ms
15,340 KB
testcase_21 AC 192 ms
15,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001

int main(){
	
	int N,Q;
	cin>>N>>Q;
	vector<int> a(N);
	rep(i,N)scanf("%d",&a[i]);
	vector<int> t = a;
	
	vector<int> l(Q),r(Q),x(Q);
	rep(i,Q){
		scanf("%d %d %d",&l[i],&r[i],&x[i]);
		r[i]--,l[i]--;
		t.push_back(x[i]);
	}
	
	sort(t.begin(),t.end());
	t.erase(unique(t.begin(),t.end()),t.end());
	
	fenwick_tree<long long> Fs(t.size()),Fc(t.size());
	
	vector<long long> ans(Q,0);
	vector<vector<pair<int,int>>> qs(N);
	rep(i,Q){
		if(l[i]!=0){
			qs[l[i]-1].emplace_back(i,-1);
		}
		qs[r[i]].emplace_back(i,1);
	}
	
	rep(i,N){
		int d = distance(t.begin(),lower_bound(t.begin(),t.end(),a[i]));
		Fc.add(d,1);
		Fs.add(d,a[i]);
		
		rep(j,qs[i].size()){
			int ii = qs[i][j].first;
			int p = distance(t.begin(),lower_bound(t.begin(),t.end(),x[ii]));
			long long S = 0;
			S += Fs.sum(0,p);
			S += Fc.sum(p,t.size())*x[ii];
			ans[ii] += S * qs[i][j].second;
		}
	}
	
	rep(i,Q){
		printf("%lld\n",ans[i]);
	}
		
		
	
	
    return 0;
}
0