結果

問題 No.877 Range ReLU Query
ユーザー tonegawatonegawa
提出日時 2020-08-12 18:26:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 343 ms / 2,000 ms
コード長 2,009 bytes
コンパイル時間 1,806 ms
コンパイル使用メモリ 128,544 KB
実行使用メモリ 23,892 KB
最終ジャッジ日時 2024-04-25 22:24:01
合計ジャッジ時間 5,911 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 325 ms
22,092 KB
testcase_12 AC 286 ms
20,688 KB
testcase_13 AC 215 ms
16,336 KB
testcase_14 AC 217 ms
16,208 KB
testcase_15 AC 343 ms
23,500 KB
testcase_16 AC 320 ms
22,620 KB
testcase_17 AC 337 ms
22,996 KB
testcase_18 AC 337 ms
22,992 KB
testcase_19 AC 278 ms
23,888 KB
testcase_20 AC 327 ms
23,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

struct segtree{
  ll M=1, INIT;
  vector<ll> dat;
  segtree(ll N, ll num){
    INIT = num;
    while(M<N) M*=2;
    for(int i=0;i<M*2-1;i++)  dat.push_back(num);
  }
  void update(ll x, ll k, ll l=0, int r=-1){
    if(r==-1) r = M;
    k+=M-1;
    dat[k] += x;
    while(k>0) k = (k-1)/2, dat[k] = dat[k*2+1] + dat[k*2+2];
  }
  ll query(ll a, ll b=-1, ll k=0, ll l=0, ll r=-1){
    if(r==-1) r = M;
    if(b==-1) b = M;
    if(r<=a || b<=l) return INIT;
    if(a<=l && r<=b) return dat[k];
    ll A = query(a, b, k*2+1, l, (l+r)/2);
    ll B = query(a, b, k*2+2, (l+r)/2, r);
    return A + B;
  }
};
typedef tuple<ll, ll, ll, ll> tp; //x, l, r, idx

int main(int argc, char const *argv[]) {
  ll n, q;std::cin >> n >> q;
  segtree seg(n+1, 0), cnt(n+1, 0);
  multiset<tp> st;
  for(int i=0;i<n;i++){
    ll t;scanf("%lld", &t);
    st.insert(tp(-t, -1, i, 0));
  }
  vll ans(q);
  for(int i=0;i<q;i++){
    ll a, b, c, d;scanf("%lld %lld %lld %lld", &a,&b,&c,&d);
    st.insert(tp(-d,b,c,i));
  }

  for(auto itr = st.begin();itr!=st.end();itr++){
    ll a = -get<0>(*itr);
    ll b = get<1>(*itr);
    ll c = get<2>(*itr);
    ll d = get<3>(*itr);
    if(b==-1) seg.update(a, c), cnt.update(1, c);
    else{
      ll S = seg.query(b-1, c);
      ll num = cnt.query(b-1, c);
      //std::cout << S << " " << num << " " << d << '\n';
      ans[d] = S - num * a;
    }
  }
  for(int i=0;i<q;i++) std::cout << ans[i] << '\n';
  return 0;
}
0