結果

問題 No.877 Range ReLU Query
ユーザー ransewhaleransewhale
提出日時 2019-09-06 23:15:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 1,641 bytes
コンパイル時間 1,806 ms
コンパイル使用メモリ 170,804 KB
実行使用メモリ 15,412 KB
最終ジャッジ日時 2024-04-25 22:07:06
合計ジャッジ時間 4,930 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,940 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 3 ms
6,948 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 169 ms
14,316 KB
testcase_12 AC 150 ms
14,944 KB
testcase_13 AC 120 ms
9,264 KB
testcase_14 AC 121 ms
11,824 KB
testcase_15 AC 180 ms
14,516 KB
testcase_16 AC 171 ms
13,916 KB
testcase_17 AC 165 ms
15,412 KB
testcase_18 AC 173 ms
14,712 KB
testcase_19 AC 125 ms
15,328 KB
testcase_20 AC 156 ms
14,864 KB
権限があれば一括ダウンロードができます

ソースコード

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;
ll segtree[410410][2],ans[100100];

vector<que> v;

void update(int p, ll v, int l=0, int r=n, int i=0){
	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