結果
| 問題 |
No.2065 Sum of Min
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2022-09-04 02:40:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,359 bytes |
| コンパイル時間 | 2,031 ms |
| コンパイル使用メモリ | 205,384 KB |
| 最終ジャッジ日時 | 2025-02-07 02:30:47 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 RE * 2 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename T>
struct BIT{
private:
vector<T> A;
const int n;
public:
BIT(int _n) : A(_n+1,0), n(_n){}
T sum(int i){
T s=0;
while(i>0){
s+=A[i];
i-=i&-i;
}
return s;
}
T sum(int i,int j){
return sum(j)-sum(i-1);
}
void add(int i,T x){
while(i<=n){
A[i]+=x;
i+=i&-i;
}
}
void update(int i,T x){
T tmp=sum(i,i);
if(tmp!=x) add(i,x-tmp);
}
};
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n,q;
cin>>n>>q;
vector<ll> A(n+1);
vector<pair<ll,ll>> C(n);
rep(i,n){
cin>>A[i+1];
C[i]={A[i+1],i+1};
}
sort(ALL(C));
vector<ll> L(q),R(q),X(q);
rep(i,q) cin>>L[i]>>R[i]>>X[i];
vector<ll> ANS(n+1);
vector<pair<ll,ll>> B(q);
rep(i,q) B[i]={X[i],i};
sort(ALL(B));
reverse(ALL(B));
BIT<ll> bit(n),bit1(n);
for(int i=1;i<=n;i++) bit.add(i,A[i]);
int now=n-1;
rep(i,q){
ll nx=B[i].first,ni=B[i].second;
while(now>=0 && C[now].first>=nx){
bit.update(C[now].second,0);
bit1.update(C[now].second,1);
now--;
}
ANS[ni]=bit.sum(L[ni],R[ni])+X[ni]*bit1.sum(L[ni],R[ni]);
}
rep(i,q) cout<<ANS[i]<<endl;
return 0;
}
umezo