結果

問題 No.877 Range ReLU Query
コンテスト
ユーザー 👑 tttmmmyyyy
提出日時 2026-10-31 08:23:34
言語 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  
実行時間 74 ms / 2,000 ms
+ 78µs
コード長 2,301 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 912 ms
コンパイル使用メモリ 127,244 KB
実行使用メモリ 15,580 KB
最終ジャッジ日時 2026-10-31 08:23:50
合計ジャッジ時間 4,002 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

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

static inline ll fast_read() {
    int c = getchar_unlocked();
    while (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\v' || c == '\f') {
        c = getchar_unlocked();
    }
    bool negative = false;
    if (c == '-' || c == '+') {
        negative = c == '-';
        c = getchar_unlocked();
    }
    ull value = 0;
    while ('0' <= c && c <= '9') {
        value = value * 10 + (ull)(c - '0');
        c = getchar_unlocked();
    }
    if (c != EOF) {
        ungetc(c, stdin);
    }
    return negative ? -(ll)value : (ll)value;
}

static inline void fast_write(ll v) {
    char buf[24];
    int n = 0;
    ull u = v < 0 ? 0ULL - (ull)v : (ull)v;
    if (v < 0) {
        putchar_unlocked('-');
    }
    do {
        buf[n++] = (char)('0' + u % 10);
        u /= 10;
    } while (u);
    while (n) {
        putchar_unlocked(buf[--n]);
    }
    putchar_unlocked('\n');
}

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

int main() {
    ll n, q;
    n = fast_read();
    q = fast_read();
    vector<ll> as(n);
    for (auto &a : as) {
        a = fast_read();
    }
    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;
        t = fast_read();
        l = fast_read();
        r = fast_read();
        x = fast_read();
        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++) {
        fast_write(ans[i]);
    }
}
0