結果
問題 | No.877 Range ReLU Query |
ユーザー |
👑 ![]() |
提出日時 | 2020-09-27 14:44:56 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 759 ms / 2,000 ms |
コード長 | 1,771 bytes |
コンパイル時間 | 2,226 ms |
コンパイル使用メモリ | 181,920 KB |
実行使用メモリ | 54,352 KB |
最終ジャッジ日時 | 2024-11-08 10:31:35 |
合計ジャッジ時間 | 10,161 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 4 ms
5,248 KB |
testcase_02 | AC | 4 ms
5,248 KB |
testcase_03 | AC | 5 ms
5,248 KB |
testcase_04 | AC | 3 ms
5,248 KB |
testcase_05 | AC | 3 ms
5,248 KB |
testcase_06 | AC | 3 ms
5,248 KB |
testcase_07 | AC | 3 ms
5,248 KB |
testcase_08 | AC | 5 ms
5,248 KB |
testcase_09 | AC | 3 ms
5,248 KB |
testcase_10 | AC | 4 ms
5,248 KB |
testcase_11 | AC | 701 ms
46,784 KB |
testcase_12 | AC | 630 ms
46,084 KB |
testcase_13 | AC | 479 ms
32,308 KB |
testcase_14 | AC | 494 ms
30,092 KB |
testcase_15 | AC | 759 ms
53,624 KB |
testcase_16 | AC | 721 ms
52,720 KB |
testcase_17 | AC | 753 ms
53,480 KB |
testcase_18 | AC | 746 ms
53,808 KB |
testcase_19 | AC | 451 ms
54,348 KB |
testcase_20 | AC | 611 ms
54,352 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; using LL = long long; using ULL = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) struct RQ { private: struct Node { vector<LL> x, s; }; int N; vector<Node> V; public: RQ(vector<LL> A) { N = 1; while (N < A.size()) N *= 2; V.assign(N * 2, { {},{} }); rep(i, A.size()) V[N + i] = { {A[i]}, {A[i],0} }; for (int i = N - 1; i >= 1; i--) { for (LL a : V[i * 2].x) V[i].x.push_back(a); for (LL a : V[i * 2 + 1].x) V[i].x.push_back(a); sort(V[i].x.begin(), V[i].x.end()); V[i].s.resize(V[i].x.size() + 1); for (int j = V[i].x.size() - 1; j >= 0; j--) V[i].s[j] = V[i].s[j + 1] + V[i].x[j]; } } LL sum(int l, int r, LL x, int a = 0, int b = 0, int i = -1) { if (i == -1) { a = 0; b = N; i = 1; } if (r <= a || b <= l) return 0; if (l <= a && b <= r) { int xl = 0, xr = V[i].x.size() + 1; while (xl + 1 < xr) { int xm = (xl + xr) / 2; if (V[i].x[xm - 1] < x) xl = xm; else xr = xm; } if (xl == V[i].x.size()) return 0; LL ans = V[i].s[xl]; ans -= (V[i].x.size() - xl) * x; return ans; } LL q1 = sum(l, r, x, a, (a + b) / 2, i * 2); LL q2 = sum(l, r, x, (a + b) / 2, b, i * 2 + 1); return q1 + q2; } }; int main() { int N, Q; cin >> N >> Q; vector<LL> A(N); rep(i, N) { cin >> A[i]; } RQ G(A); while (Q--) { int c; cin >> c; if (c == 1) { int l, r, x; cin >> l >> r >> x; l--; cout << G.sum(l, r, x) << endl; } } return 0; }