結果

問題 No.877 Range ReLU Query
ユーザー Ricky_ponRicky_pon
提出日時 2020-09-18 20:39:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,372 bytes
コンパイル時間 2,163 ms
コンパイル使用メモリ 204,640 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-04 09:10:01
合計ジャッジ時間 7,864 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,500 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int width = 2;
lint asum[350 * 300];
pair<lint, int> a[350 * 300];

lint get_sum(int k, lint x) {
    int i =
        upper_bound(a + k * width, a + (k + 1) * width, make_pair(x, -1)) - a;
    return asum[(k + 1) * width] - asum[i] - x * ((k + 1) * width - i);
}

lint get_backet_sum(int k, lint x, int l, int r) {
    lint ret = 0;
    For(i, k * width, (k + 1) * width) if (l <= a[i].se && a[i].se < r) {
        ret += max(0LL, a[i].fi - x);
    }
    return ret;
}

int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    int num = div_ceil(n, width);
    rep(i, num * width) a[i] = {-1, -1};
    rep(i, n) {
        scanf("%lld", &a[i].fi);
        a[i].se = i;
    }
    rep(k, num) sort(a + k * width, a + (k + 1) * width);
    rep(i, num * width) asum[i + 1] = asum[i] + a[i].fi;

    rep(_, q) {
        int t, l, r;
        lint x;
        scanf("%d%d%d%lld", &t, &l, &r, &x);
        --l;
        lint ans = 0;
        For(k, div_ceil(l, width), div_floor(r, width)) {
            ans += get_sum(k, x);
        }
        if (l % width != 0 || div_floor(l, width) == div_floor(r, width)) {
            ans += get_backet_sum(div_floor(l, width), x, l, r);
        }
        if (r % width != 0 && div_floor(l, width) != div_floor(r, width)) {
            ans += get_backet_sum(div_floor(r, width), x, l, r);
        }
        printf("%lld\n", ans);
    }
}
0