結果

問題 No.877 Range ReLU Query
ユーザー Y17Y17
提出日時 2019-09-06 22:24:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 363 ms / 2,000 ms
コード長 2,152 bytes
コンパイル時間 1,854 ms
コンパイル使用メモリ 178,876 KB
実行使用メモリ 13,036 KB
最終ジャッジ日時 2023-09-07 05:50:27
合計ジャッジ時間 7,160 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 348 ms
12,388 KB
testcase_12 AC 306 ms
12,508 KB
testcase_13 AC 245 ms
9,336 KB
testcase_14 AC 255 ms
9,052 KB
testcase_15 AC 362 ms
12,928 KB
testcase_16 AC 347 ms
12,648 KB
testcase_17 AC 350 ms
12,772 KB
testcase_18 AC 346 ms
12,568 KB
testcase_19 AC 332 ms
13,036 KB
testcase_20 AC 363 ms
12,972 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:84:21: 警告: ‘lp’ may be used uninitialized [-Wmaybe-uninitialized]
   84 |         while(vec[lp].first <= x){
      |                     ^
main.cpp:73:9: 備考: ‘lp’ はここで定義されています
   73 |     int lp;
      |         ^~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long

template <class Monoid> struct SegmentTree{
    using Func = function<Monoid(Monoid, Monoid)>;

    int size;
    vector<Monoid> seg;
    const Func merge;
    const Monoid def;

    SegmentTree(int n, Monoid d, const Func f): merge(f), def(d){
        for(size = 1; size <= n; size <<= 1);
        seg.assign(size*2, def);
    }

    Monoid& operator[] (int i) { return seg[i+size]; };
    void build(){ for(int i = size-1;i >= 0;i--) seg[i] = merge(seg[i*2], seg[i*2+1]); }

    void update(int i, Monoid val){
        seg[i += size] = val;
        while(i >>= 1) seg[i] = merge(seg[i*2], seg[i*2+1]);
    }

    void add(int i, Monoid val){ update(i, val+seg[i+size]); }

    Monoid get(int a, int b){
        Monoid l = def, r = def;
        for(a += size, b += size; a < b; a >>= 1, b >>= 1){
            if(a & 1) l = merge(l, seg[a++]);
            if(b & 1) r = merge(r, seg[--b]);
        }
        return merge(l, r);
    }
};

int ans[100010] = {};
int ll[100010], rr[100010];
signed main(){
    int n, q;
    cin >> n >> q;

    typedef pair<int, int> P;

    SegmentTree<P> seg(n, {0, 0}, [](P a, P b){
            return make_pair(a.first + b.first, a.second + b.second);
            });

    vector<P> vec;
    for(int i = 0;i < n;i++){
        int a;
        cin >> a;
        seg[i] = {a, 1};
        vec.push_back({a, i});
    }

    seg.build();

    sort(vec.begin(), vec.end());

    priority_queue<P, vector<P>, greater<P>> que;


    for(int i = 0;i < q;i++){
        int a, x;
        cin >> a >> ll[i] >> rr[i] >> x;
        ll[i]--;
        que.push({x, i});
    }

    int lp;
    vec.push_back({1000000007, 0});

    while(!que.empty()){

        int idx = que.top().second;
        int x = que.top().first;
        int l = ll[idx];
        int r = rr[idx];
        que.pop();

        while(vec[lp].first <= x){
            seg.update(vec[lp].second, {0, 0});
            lp++;
        }

        auto a = seg.get(l, r);
        ans[idx] = a.first - a.second*x;
    }

    for(int i = 0;i < q;i++){
        cout << ans[i] << endl;
    }

    return 0;
}
0