結果

問題 No.877 Range ReLU Query
ユーザー cho435cho435
提出日時 2023-04-22 16:09:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 783 bytes
コンパイル時間 2,821 ms
コンパイル使用メモリ 210,260 KB
実行使用メモリ 19,840 KB
最終ジャッジ日時 2024-04-24 19:37:54
合計ジャッジ時間 6,822 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 249 ms
18,132 KB
testcase_12 AC 218 ms
17,280 KB
testcase_13 AC 173 ms
13,468 KB
testcase_14 AC 178 ms
13,356 KB
testcase_15 AC 263 ms
19,400 KB
testcase_16 AC 251 ms
18,944 KB
testcase_17 AC 259 ms
19,360 KB
testcase_18 AC 255 ms
19,144 KB
testcase_19 AC 254 ms
19,840 KB
testcase_20 AC 250 ms
19,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/segtree>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i=0;i<(int)(n);i++)

struct S{
  ll val;
  ll sz;
};
S op(S a,S b){
  return {a.val+b.val,a.sz+b.sz};
}
S e(){
  return {0,0};
}

int main(){
  int n,q;
  cin>>n>>q;
  vector<vector<int>> p(n+q);
  rep(i,n){
    int a;
    cin>>a;
    p.at(i)={a,2,i};
  }
  rep(i,q){
    int t,l,r,x;
    cin>>t>>l>>r>>x;
    l--;
    p.at(n+i)={x,1,l,r,i};
  }
  sort(p.begin(),p.end(),greater<vector<int>>());
  atcoder::segtree<S,op,e> seg(n);
  vector<ll> ans(q);
  for(auto &v:p){
    if(v.at(1)==1){
      S s=seg.prod(v.at(2),v.at(3));
      ans.at(v.at(4))=s.val-s.sz*v.at(0);
    }else{
      seg.set(v.at(2),{v.at(0),1});
    }
  }
  rep(i,q) cout<<ans.at(i)<<'\n';
}
0