結果
| 問題 |
No.877 Range ReLU Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-30 16:11:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 285 ms / 2,000 ms |
| コード長 | 998 bytes |
| コンパイル時間 | 2,426 ms |
| コンパイル使用メモリ | 214,204 KB |
| 最終ジャッジ日時 | 2025-02-26 09:40:23 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
#include<atcoder/segtree>
using namespace atcoder;
using S=pair<ll,ll>;
S op(S a, S b){
a.first+=b.first;
a.second+=b.second;
return a;
}
S e(){
return make_pair(0,0);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,q;
cin>>n>>q;
vector<int> a(n);
rep(i,n)cin>>a[i];
vector<vector<int>> ev(n);
rep(i,n) ev[i] = {a[i],i};
rep(i,q){
int t,l,r,x;
cin>>t>>l>>r>>x;
l--;
ev.push_back({x,l,r,i});
}
sort(ev.begin(),ev.end());
vector<ll> ans(q);
segtree<S,op,e> seg(n);
rep(i,n) seg.set(i, make_pair(a[i],1));
for(auto v: ev){
if(v.size()==2){
seg.set(v[1], make_pair(0,0));
}
else{
S s = seg.prod(v[1],v[2]);
ans[v[3]] = s.first-s.second*v[0];
}
}
rep(i,q)cout<<ans[i]<<endl;
}