結果

問題 No.877 Range ReLU Query
ユーザー tonegawatonegawa
提出日時 2020-08-12 18:27:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 1,693 bytes
コンパイル時間 1,356 ms
コンパイル使用メモリ 127,520 KB
実行使用メモリ 23,936 KB
最終ジャッジ日時 2024-04-25 22:24:51
合計ジャッジ時間 4,831 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 192 ms
22,016 KB
testcase_12 AC 168 ms
20,864 KB
testcase_13 AC 125 ms
16,256 KB
testcase_14 AC 129 ms
16,512 KB
testcase_15 AC 206 ms
23,296 KB
testcase_16 AC 200 ms
22,784 KB
testcase_17 AC 204 ms
23,168 KB
testcase_18 AC 201 ms
23,040 KB
testcase_19 AC 198 ms
23,936 KB
testcase_20 AC 204 ms
23,936 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 BIT{
  ll M=1;
  vector<ll> dat;
  BIT(ll N){
    while(N>M) M*=2;
    dat.resize(M*2-1, 0);
  }
  void update(ll x, ll k){
    for(int i=k+1;i<=M;i+=(i&(-i))){
      dat[i] += x;
    }
  }
  ll sum(ll r){
    ll ret = 0;
    for(int k=r;k>0;k-=(k&(-k))) ret += dat[k];
    return ret;
  }

  ll query(ll l, ll r){
    return sum(r) - sum(l);
  }
};
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;
  BIT seg(n+1), cnt(n+1);
  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);
      ans[d] = S - num * a;
    }
  }
  for(int i=0;i<q;i++) printf("%lld\n", ans[i]);
  return 0;
}
0