結果

問題 No.2065 Sum of Min
ユーザー 👑 kmjpkmjp
提出日時 2022-09-02 22:46:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 216 ms / 2,000 ms
コード長 1,553 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 206,724 KB
実行使用メモリ 19,148 KB
最終ジャッジ日時 2023-08-10 05:03:51
合計ジャッジ時間 8,528 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
15,716 KB
testcase_01 AC 4 ms
15,708 KB
testcase_02 AC 4 ms
15,768 KB
testcase_03 AC 4 ms
15,716 KB
testcase_04 AC 196 ms
18,988 KB
testcase_05 AC 197 ms
19,040 KB
testcase_06 AC 190 ms
18,972 KB
testcase_07 AC 182 ms
18,984 KB
testcase_08 AC 200 ms
19,036 KB
testcase_09 AC 200 ms
18,920 KB
testcase_10 AC 204 ms
19,108 KB
testcase_11 AC 199 ms
18,968 KB
testcase_12 AC 216 ms
19,020 KB
testcase_13 AC 205 ms
19,140 KB
testcase_14 AC 206 ms
19,092 KB
testcase_15 AC 204 ms
18,912 KB
testcase_16 AC 212 ms
19,128 KB
testcase_17 AC 212 ms
18,928 KB
testcase_18 AC 208 ms
19,056 KB
testcase_19 AC 206 ms
19,056 KB
testcase_20 AC 214 ms
18,860 KB
testcase_21 AC 211 ms
19,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,Q;
int A[101010];
int L[101010],R[101010],X[101010];
ll ret[202020];
template<class V, int ME> class BIT {
public:
	V bit[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { e++; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};
BIT<ll,20> num,sum;



void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q;
	vector<pair<int,int>> ev;
	FOR(i,N) {
		cin>>A[i];
		num.add(i,1);
		ev.push_back({A[i],i});
	}
	FOR(i,Q) {
		cin>>L[i]>>R[i]>>X[i];
		ev.push_back({X[i],N+i});
	}
	sort(ALL(ev));
	FORR2(v,i,ev) {
		if(i<N) {
			num.add(i,-1);
			sum.add(i,A[i]);
		}
		else {
			i-=N;
			ret[i]=sum(R[i]-1)-sum(L[i]-2)+X[i]*(num(R[i]-1)-num(L[i]-2));
		}
	}
	FOR(i,Q) cout<<ret[i]<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0