結果

問題 No.877 Range ReLU Query
ユーザー 0w10w1
提出日時 2019-10-09 12:52:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,616 bytes
コンパイル時間 2,448 ms
コンパイル使用メモリ 213,564 KB
実行使用メモリ 14,020 KB
最終ジャッジ日時 2023-08-10 00:18:51
合計ジャッジ時間 9,481 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,628 KB
testcase_01 AC 6 ms
11,812 KB
testcase_02 AC 7 ms
11,648 KB
testcase_03 AC 8 ms
11,652 KB
testcase_04 AC 6 ms
11,544 KB
testcase_05 AC 6 ms
11,552 KB
testcase_06 AC 6 ms
11,500 KB
testcase_07 AC 5 ms
11,500 KB
testcase_08 AC 8 ms
11,512 KB
testcase_09 AC 5 ms
11,508 KB
testcase_10 AC 7 ms
11,508 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<int n>
struct Segt {
  int64_t sumv[n * 4];
  Segt() { memset(sumv, 0x00, sizeof(sumv)); }
  void update(int v, int k, int lb = 0, int rb = n, int t = 1) {
    if (rb - lb == 1) {
      sumv[t] += v;
      return;
    }
    int mb = lb + rb >> 1;
    if (k < mb) update(v, k, lb, mb, t << 1);
    else update(v, k, mb, rb, t << 1 | 1);
    sumv[t] = sumv[t << 1] + sumv[t << 1 | 1];
  }
  int64_t query(int ql, int qr, int lb = 0, int rb = n, int t = 1) {
    if (qr <= lb || rb <= ql) return 0LL;
    if (ql <= lb && rb <= qr) return sumv[t];
    int mb = lb + rb >> 1; return query(ql, qr, lb, mb, t << 1) + query(ql, qr, mb, rb, t << 1 | 1);
  }
};

int main() {
  int N, Q;
  cin >> N >> Q;

  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  vector<tuple<int, int, int>> T(Q);
  for (int i = 0; i < Q; ++i) {
    int P, L, R, X;
    cin >> P >> L >> R >> X;
    T[i] = make_tuple(X, L, R);
  }

  vector<int> ord(N + Q);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](int i, int j) {
    auto f = [&](int x) { return x < N ? A[x] : get<0>(T[x - N]); };
    return f(i) > f(j);
  });

  vector<int> ans(Q);
  Segt<(1 << 17)> stree;
  Segt<(1 << 17)> ctree;
  for (int i = 0; i < N + Q; ++i) {
    int o = ord[i];
    if (o < N) {
      stree.update(A[o], o);
      ctree.update(1, o);
    } else {
      int x, l, r;
      tie(x, l, r) = T[o - N];
      ans[o - N] = stree.query(l - 1, r) - ctree.query(l - 1, r) * x;
    }
  }

  for (int i = 0; i < Q; ++i) {
    cout << ans[i] << endl;
  }

  return 0;
}
0