結果

問題 No.877 Range ReLU Query
ユーザー SugarDragon5SugarDragon5
提出日時 2019-09-06 23:14:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 341 ms / 2,000 ms
コード長 1,892 bytes
コンパイル時間 1,889 ms
コンパイル使用メモリ 175,472 KB
実行使用メモリ 16,052 KB
最終ジャッジ日時 2023-08-08 04:25:03
合計ジャッジ時間 6,938 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 330 ms
14,440 KB
testcase_12 AC 292 ms
13,808 KB
testcase_13 AC 231 ms
9,652 KB
testcase_14 AC 247 ms
12,164 KB
testcase_15 AC 340 ms
14,108 KB
testcase_16 AC 330 ms
15,108 KB
testcase_17 AC 341 ms
13,816 KB
testcase_18 AC 335 ms
13,892 KB
testcase_19 AC 330 ms
15,068 KB
testcase_20 AC 332 ms
16,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
struct Tree{
    int n;
    vector<ll> vec;
    Tree(int _n){
        n=1;
        while(n<_n){
            n*=2;
        }
        vec.assign(n*2+10,0);
    }
    void update(int k,ll x){
        k+=n;
        vec[k]=x;
        k/=2;
        while(k){
            vec[k]=vec[k*2]+vec[k*2+1];
            k/=2;
        }
    }
    ll sum(int l,int r){
        ll ans=0;
        l+=n;
        r+=n;
        while(l<r){
            if(l%2){
                ans+=vec[l];
                l++;
            }
            if(r%2){
                ans+=vec[r-1];
                r--;
            }
            l/=2;
            r/=2;
        }
        return ans;
    }

};
struct Query{
    int f;
    ll x;
    int l,r;
    int n;
    Query(int n,ll x):f(0),n(n),l(n),r(n),x(x){}
    Query(int n,int l,int r,ll x):n(n),f(1),l(l),r(r),x(x){}
    bool operator<(const Query &o){
        if(x==o.x){
            if(f==o.f){
                if(n==o.n){
                    return P(l,r)>P(o.l,o.r);
                }
                return n>o.n;
            }
            return f>o.f;
        }
        return x>o.x;
    }
};
int main(){
    int n,m;
    cin>>n>>m;
    vector<Query> que;
    for(int i=0;i<n;i++){
        ll t;
        cin>>t;
        que.push_back(Query(i,t));
    }
    for(int i=0;i<m;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        b--;c--;
        que.push_back(Query(i,b,c,d));
    }
    sort(que.begin(),que.end());
    Tree tr(n);
    Tree cn(n);
    vector<ll> ans(m);
    for(int i=0;i<que.size();i++){
        Query t=que[i];
        if(t.f){
            ans[t.n]=tr.sum(t.l,t.r+1)-cn.sum(t.l,t.r+1)*t.x;
        }else{
            tr.update(t.n,t.x);
            cn.update(t.n,1);
        }
    }
    for(int i=0;i<m;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}
0