結果

問題 No.877 Range ReLU Query
ユーザー ransewhaleransewhale
提出日時 2019-09-06 23:15:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,653 bytes
コンパイル時間 1,846 ms
コンパイル使用メモリ 170,156 KB
実行使用メモリ 13,556 KB
最終ジャッジ日時 2023-09-07 02:29:34
合計ジャッジ時間 5,385 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 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 #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

struct que{
	int t,i,l,r;
	ll x;
	bool operator<(const que &rhs){
		return (x<rhs.x);
	}
};

int n,segtree[410410][2];
ll ans[100100];

vector<que> v;

void update(int p, ll v, int l=0, int r=n, int i=0){
	int vl,vr;
	if(p<l || r<=p){
		return;
	}else if(r-l>1){
		update(p,v,l,(l+r)>>1,i*2+1);
		update(p,v,(l+r)>>1,r,i*2+2);
		segtree[i][0] = segtree[i*2+1][0]+segtree[i*2+2][0];
		segtree[i][1] = segtree[i*2+1][1]+segtree[i*2+2][1];
	}else{
		segtree[i][0] = v;
		if(v){
			segtree[i][1] = 1;
		}else{
			segtree[i][1] = 0;
		}
	}
}

ll query(int k, int p, int q, int l=0, int r=n, int i=0){
	ll vl,vr;
	if(q<=l || r<=p){
		return 0ll;
	}else if(p<=l && r<=q){
		return segtree[i][k];
	}else{
		vl = query(k,p,q,l,(l+r)>>1,i*2+1);
		vr = query(k,p,q,(l+r)>>1,r,i*2+2);
		return vl+vr;
	}
}

int main(void){
	int q,i;
	ll a;
	que qu;
	qu.t = 0;
	scanf("%d%d",&n,&q);
	for(i=0; i<n; ++i){
		qu.i = i;
		scanf("%lld",&qu.x);
		update(qu.i,qu.x);
		v.push_back(qu);
	}
	for(i=0; i<q; ++i){
		qu.i = i;
		scanf("%d%d%d%lld",&qu.t,&qu.l,&qu.r,&qu.x);
		--qu.l;
		v.push_back(qu);
	}
	sort(v.begin(),v.end());
	for(i=0; i<(q+n); ++i){
		if(v[i].t){
			ans[v[i].i] = query(0,v[i].l,v[i].r)-query(1,v[i].l,v[i].r)*v[i].x;
		}else{
			update(v[i].i,0ll);
		}
	}
	for(i=0; i<q; ++i){
		printf("%lld\n",ans[i]);
	}
	return 0;
}
0