結果

問題 No.877 Range ReLU Query
コンテスト
ユーザー 👑 tttmmmyyyy
提出日時 2026-10-31 08:22:05
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 96 ms / 2,000 ms
+ 323µs
コード長 1,326 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 889 ms
コンパイル使用メモリ 126,348 KB
実行使用メモリ 16,232 KB
最終ジャッジ日時 2026-10-31 08:22:22
合計ジャッジ時間 5,659 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <algorithm>
#include <cstdio>
#include <tuple>
#include <utility>
#include <vector>
#include <atcoder/segtree>

using namespace std;
using namespace atcoder;
using ll = long long;

ll op(ll a, ll b) {
    return a + b;
}
ll e() {
    return 0;
}

int main() {
    ll n, q;
    scanf("%lld %lld", &n, &q);
    vector<ll> as(n);
    for (auto &a : as) {
        scanf("%lld", &a);
    }
    vector<pair<ll, ll>> as_sorted(n);
    for (ll i = 0; i < n; i++) {
        as_sorted[i] = {i, as[i]};
    }
    sort(as_sorted.begin(), as_sorted.end(), [](auto &a, auto &b) { return a.second > b.second; });
    segtree<ll, op, e> tree(n), cnt(n);
    vector<tuple<ll, ll, ll, ll>> qs;
    for (ll i = 0; i < q; i++) {
        ll t, l, r, x;
        scanf("%lld %lld %lld %lld", &t, &l, &r, &x);
        qs.push_back({i, l - 1, r, x});
    }
    sort(qs.begin(), qs.end(), [](auto &a, auto &b) { return get<3>(a) > get<3>(b); });
    vector<ll> ans(q, 0);
    ll k = 0;
    for (auto &[i, l, r, x] : qs) {
        while (k < n && as_sorted[k].second >= x) {
            tree.set(as_sorted[k].first, as_sorted[k].second);
            cnt.set(as_sorted[k].first, 1);
            k++;
        }
        ans[i] = tree.prod(l, r) - x * cnt.prod(l, r);
    }
    for (ll i = 0; i < q; i++) {
        printf("%lld\n", ans[i]);
    }
}
0