結果

問題 No.877 Range ReLU Query
ユーザー ttttan2ttttan2
提出日時 2019-09-06 22:51:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 2,822 bytes
コンパイル時間 1,713 ms
コンパイル使用メモリ 170,896 KB
実行使用メモリ 15,636 KB
最終ジャッジ日時 2024-04-25 22:05:58
合計ジャッジ時間 4,890 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 3 ms
6,816 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 208 ms
11,824 KB
testcase_12 AC 180 ms
11,372 KB
testcase_13 AC 146 ms
9,980 KB
testcase_14 AC 157 ms
10,296 KB
testcase_15 AC 213 ms
15,636 KB
testcase_16 AC 203 ms
13,932 KB
testcase_17 AC 203 ms
12,116 KB
testcase_18 AC 201 ms
11,880 KB
testcase_19 AC 206 ms
12,328 KB
testcase_20 AC 215 ms
12,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll bit[800010];
ll u;
void bitinit(ll n){
    ll y=1;
    rep(i,0,69){
        
        if(y>=n){
            u=y;
            break;
        }
        y*=2;
    }
    fill(bit,bit+u+10,0);
}
void add(ll n,ll x){
    ll i=n;
    bit[i]+=x;
   
    while(i<u){
        i+=i&(-i);
        bit[i]+=x;
        
    }
}
ll bit2[800010];
ll u2;
void bitinit2(ll n){
    ll y=1;
    rep(i,0,69){
        
        if(y>=n){
            u=y;
            break;
        }
        y*=2;
    }
    fill(bit2,bit2+u2+10,0);
}
void add2(ll n,ll x){
    ll i=n;
    bit2[i]+=x;
    
    while(i<u){
        i+=i&(-i);
        bit2[i]+=x;
       
    }
}
ll sum(ll n){
    ll i=n;
    ll ret=0;
    while(i>0){
        ret+=bit[i];
        i-=i&(-i);
       
    }
    return ret;
}
ll sum2(ll n){
    ll i=n;
    ll ret=0;
    while(i>0){
        ret+=bit2[i];
        i-=i&(-i);
        
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,q;cin>>n>>q;
    bitinit(n);
    bitinit2(n);
    vector<pll> v;
    rep(i,1,n+1){
        ll a;cin>>a;
        v.push_back({a,i});
    }
    sort(v.begin(),v.end(),greater<pll>());
    ll l[q],r[q],x[q];
    vector<pll> w;
    rep(i,0,q){
        ll ff;cin>>ff;
        cin>>l[i]>>r[i]>>x[i];
        w.push_back({x[i],i});
    }
    sort(w.begin(),w.end(),greater<pll>());
    ll now=0;
    ll ans[q];
    set<ll> st;
    rep(i,0,w.size()){
        ll nl=l[w[i].second];
        ll nr=r[w[i].second];
        ll nx=x[w[i].second];
        while(now<n&&v[now].first>=nx){
            add(v[now].second,v[now].first);
            add2(v[now].second,1);
            now++;
        }
        ll ss=sum(nr)-sum(nl-1);
        ll tt=sum2(nr)-sum2(nl-1);
        ss-=tt*nx;
        ans[w[i].second]=ss;
    }
    rep(i,0,q)cout<<ans[i]<<endl;
}
        
0