結果

問題 No.877 Range ReLU Query
ユーザー niuezniuez
提出日時 2019-09-06 22:45:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 316 ms / 2,000 ms
コード長 2,495 bytes
コンパイル時間 1,997 ms
コンパイル使用メモリ 181,180 KB
実行使用メモリ 19,004 KB
最終ジャッジ日時 2024-04-25 22:05:13
合計ジャッジ時間 6,260 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 304 ms
16,672 KB
testcase_12 AC 265 ms
16,980 KB
testcase_13 AC 214 ms
13,424 KB
testcase_14 AC 230 ms
13,032 KB
testcase_15 AC 316 ms
19,004 KB
testcase_16 AC 290 ms
17,996 KB
testcase_17 AC 300 ms
17,576 KB
testcase_18 AC 297 ms
17,740 KB
testcase_19 AC 304 ms
17,564 KB
testcase_20 AC 302 ms
18,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const
 
struct segment_tree {
  using T = pair<i64, i64>;
  T ope(const T& a, const T& b) {
    return { a.first + b.first , a.second + b.second };
  }
  T ide() { return { 0, 0 }; }
 
  i64 n;
  vector<T> node;
 
  segment_tree(vector<T> init) {
    n = 1;
    while(n < init.size()) n *= 2;
    node.resize(2 * n);
    rep(i, 0, init.size()) node[i + n] = init[i];
    for(int i = n - 1; i >= 1;i--) node[i] = ope(node[i * 2], node[i * 2 + 1]);
  }
 
  void update(i64 i, T x) {
    i += n;
    node[i] = x;
    while(i > 1) {
      i = i / 2;
      node[i] = ope(node[i * 2], node[i * 2 + 1]);
    }
  }
  
  /* [l, r] */
  T get(i64 l, i64 r) {
    T lx = ide();
    T rx = ide();
    l += n;
    r += n;
    while(l < r) {
      if(l & 1) { lx = ope(lx, node[l]); }
      if(!(r & 1)) { rx = ope(node[r], rx); }
      l = (l + 1) >> 1;
      r = (r - 1) >> 1;
    }
    if(l == r) { lx = ope(lx, node[l]); }
    return ope(lx, rx);
  }
};
int main() {
  i64 n, q;
  cin >> n >> q;
  vector<i64> a(n);
  vector<pair<i64, i64>> vec;
  vector<pair<i64, i64>> vec2;
  rep(i,0,n) cin >> a[i];
  rep(i,0,n) vec.push_back({ a[i], i });
  rep(i,0,n) vec2.push_back({ a[i], 1 });
  segment_tree seg(vec2);
  sort(all(vec));
  i64 ii = 0;
  vector<pair<pair<i64,i64>, pair<i64, i64>>> query;
  rep(i,0,q) {
    i64 com, l, r, x;
    cin >> com >> l >> r >> x;
    query.push_back({ {x, i}, { l, r } });
  }
  vector<i64> ans(q);
  sort(all(query));
  for(auto qq: query) {
    i64 l = qq.second.first;
    i64 r = qq.second.second;
    i64 x = qq.first.first;
    i64 ai = qq.first.second;
    while(ii < vec.size() && vec[ii].first - x <= 0) {
      i64 i = vec[ii].second;
      seg.update(i,{0, 0});
      ii++;
    }
    auto res = seg.get(l - 1, r - 1);
    ans[ai] = res.first - res.second * x;
  }
  rep(i,0,q) {
    cout << ans[i] << endl;
  }
}
0