結果

問題 No.877 Range ReLU Query
ユーザー merom686merom686
提出日時 2019-09-06 22:56:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,705 bytes
コンパイル時間 1,296 ms
コンパイル使用メモリ 94,120 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-04-25 22:05:52
合計ジャッジ時間 3,380 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 74 ms
8,192 KB
testcase_12 AC 67 ms
7,808 KB
testcase_13 AC 54 ms
6,940 KB
testcase_14 AC 56 ms
7,040 KB
testcase_15 AC 79 ms
8,704 KB
testcase_16 AC 76 ms
8,476 KB
testcase_17 AC 80 ms
8,576 KB
testcase_18 AC 79 ms
8,448 KB
testcase_19 AC 77 ms
8,704 KB
testcase_20 AC 79 ms
8,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <array>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    P &operator+=(const P &p) {
        s += p.s;
        c += p.c;
        return *this;
    }
    ll s;
    int c;
};

struct BIT {
    BIT(int n) : b(n + 1), n(n) {}
    void add(int i, P v) {
        for (int k = i + 1; k <= n; k += k & -k) b[k] += v;
    }
    P sum(int k) {
        P s = { 0, 0 };
        for (; k > 0; k -= k & -k) s += b[k];
        return s;
    }
    vector<P> b;
    int n;
};

struct Q {
    bool operator<(const Q &q) const {
        return x > q.x;
    }
    ll s;
    int l, r, x, h;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end(), greater<>());

    vector<Q> q(m);
    for (int h = 0; h < m; h++) {
        int t, l, r, x;
        cin >> t >> l >> r >> x;
        l--;

        q[h] = { 0, l, r, x, h };
    }
    sort(q.begin(), q.end());

    BIT bt(n);
    int i = 0;
    for (int h = 0; h < m; h++) {
        int x = q[h].x;
        for (; i < n && a[i].first > x; i++) {
            bt.add(a[i].second, { a[i].first, 1 });
        }
        P p0 = bt.sum(q[h].l);
        P p1 = bt.sum(q[h].r);
        q[h].s = (p1.s - p0.s) - (p1.c - p0.c) * (ll)x;
    }

    vector<ll> r(m);
    for (int h = 0; h < m; h++) {
        r[q[h].h] = q[h].s;
    }
    for (int h = 0; h < m; h++) {
        cout << r[h] << '\n';
    }

    return 0;
}
0