結果

問題 No.877 Range ReLU Query
ユーザー definedefine
提出日時 2019-09-08 19:32:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 323 ms / 2,000 ms
コード長 2,551 bytes
コンパイル時間 2,068 ms
コンパイル使用メモリ 177,100 KB
実行使用メモリ 15,344 KB
最終ジャッジ日時 2024-04-25 22:13:01
合計ジャッジ時間 6,568 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 4 ms
6,940 KB
testcase_02 AC 4 ms
6,944 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 310 ms
14,644 KB
testcase_12 AC 279 ms
14,196 KB
testcase_13 AC 219 ms
10,140 KB
testcase_14 AC 243 ms
14,080 KB
testcase_15 AC 323 ms
14,988 KB
testcase_16 AC 302 ms
14,316 KB
testcase_17 AC 309 ms
15,172 KB
testcase_18 AC 308 ms
14,400 KB
testcase_19 AC 317 ms
15,344 KB
testcase_20 AC 321 ms
14,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define PP pair<P,P>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	random_device rnd;
	mt19937_64 mt64(rnd());
	uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/


struct BIT {
	int size;
	vector<int>bit, ko;
	BIT(int x) {
		size = x + 1;
		bit.resize(size, 0);
		ko.resize(size, 0);
	}
	P sum(int x) {
		P s = { 0,0 };
		while (x) {
			s.first += bit[x];
			s.second += ko[x];
			x -= x & -x;
		}
		return s;
	}
	void add(int x, int y) {
		while (x < size) {
			bit[x] += y;
			ko[x]++;
			x += x & -x;
		}
	}
};
int n, q;
struct info {
	int type, x, l, r, index;
	bool operator<(const info& a)const {
		return x > a.x;
	}
	bool operator>(const info& a)const {
		return x < a.x;
	}
};
vector<info>query;
int ans[114514];
signed main() {
	cin >> n >> q;
	rep(i, n) {
		int a; cin >> a;
		query.push_back({ 1,a,i + 1,i + 1 ,0 });
	}
	rep(i, q) {
		int l, r, x; cin >> l >> l >> r >> x;
		query.push_back({ 2,x,l,r,i });
	}
	sort(all(query));
	BIT B(n);
	for (info p : query) {
		if (p.type == 1) {
			B.add(p.l, p.x);
		}
		else {
			P ri = B.sum(p.r);
			P le = (p.l != 1 ? B.sum(p.l - 1) : P{ 0, 0 });
			ans[p.index] = ri.first - le.first - p.x * (ri.second - le.second);
		}
	}
	rep(i, q) {
		cout << ans[i] << endl;
	}
}
0