結果

問題 No.877 Range ReLU Query
ユーザー tko919tko919
提出日時 2019-09-07 11:14:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 1,713 bytes
コンパイル時間 1,649 ms
コンパイル使用メモリ 173,296 KB
実行使用メモリ 9,088 KB
最終ジャッジ日時 2024-04-25 22:10:33
合計ジャッジ時間 5,005 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 181 ms
8,192 KB
testcase_12 AC 160 ms
7,808 KB
testcase_13 AC 130 ms
6,944 KB
testcase_14 AC 136 ms
7,168 KB
testcase_15 AC 197 ms
8,704 KB
testcase_16 AC 182 ms
8,448 KB
testcase_17 AC 193 ms
8,576 KB
testcase_18 AC 187 ms
8,704 KB
testcase_19 AC 182 ms
9,088 KB
testcase_20 AC 187 ms
8,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end

ll bit[100010],bit2[100010],n;
void add(int i,int a){
	i++;
	while(i<=n){
		bit[i]+=a;
		i+=(i&-i);
	}
}
ll sum(int i){
	ll res=0; i++;
	while(i){
        res+=bit[i];
		i-=(i&-i);
	}
	return res;
}
void add2(int i,int a){
	i++;
	while(i<=n){
		bit2[i]+=a;
		i+=(i&-i);
	}
}
ll sum2(int i){
	ll res=0; i++;
	while(i){
        res+=bit2[i];
		i-=(i&-i);
	}
	return res;
}
vector<ll> a,x;
bool cmp(int i,int j){return a[i]<a[j];}
bool cmp2(int i,int j){return x[i]<x[j];}

int main(){
   int q; cin>>n>>q; a.resize(n);
   vector<int> pri(n),pri2(q);
   rep(i,0,n)cin>>a[i];
   iota(ALL(pri),0); iota(ALL(pri2),0); sort(ALL(pri),cmp);
   vector<int> l(q),r(q); x.resize(q);
   int tmp;
   rep(i,0,q)cin>>tmp>>l[i]>>r[i]>>x[i];
   sort(ALL(pri2),cmp2);
   int idx=0;
   rep(i,0,n){add(i,1); add2(i,a[i]);}
   vector<ll> ans(q);
   for(int i:pri2){
   	while(idx<n&&a[pri[idx]]<x[i]){
   		add(pri[idx],-1); add2(pri[idx],-a[pri[idx]]); idx++;
   	}
   	ans[i]=(sum2(r[i]-1)-sum2(l[i]-2))-1LL*x[i]*(sum(r[i]-1)-sum(l[i]-2));
   }
   rep(i,0,q)printf("%lld\n",ans[i]);
   return 0;
}
0