結果

問題 No.877 Range ReLU Query
ユーザー tko919tko919
提出日時 2019-09-07 11:11:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,711 bytes
コンパイル時間 2,009 ms
コンパイル使用メモリ 173,264 KB
実行使用メモリ 7,236 KB
最終ジャッジ日時 2023-09-08 13:13:51
合計ジャッジ時間 5,093 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

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

int 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<int> 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))-x[i]*(sum(r[i]-1)-sum(l[i]-2));
   }
   rep(i,0,q)printf("%lld\n",ans[i]);
   return 0;
}
0