結果

問題 No.877 Range ReLU Query
ユーザー 夜
提出日時 2021-03-04 19:58:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 307 ms / 2,000 ms
コード長 1,781 bytes
コンパイル時間 1,267 ms
コンパイル使用メモリ 109,148 KB
実行使用メモリ 12,052 KB
最終ジャッジ日時 2024-04-25 22:29:51
合計ジャッジ時間 5,861 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 5 ms
6,944 KB
testcase_02 AC 5 ms
8,608 KB
testcase_03 AC 6 ms
8,452 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 5 ms
8,464 KB
testcase_06 AC 4 ms
8,456 KB
testcase_07 AC 5 ms
8,604 KB
testcase_08 AC 6 ms
8,492 KB
testcase_09 AC 4 ms
8,472 KB
testcase_10 AC 5 ms
6,940 KB
testcase_11 AC 294 ms
11,696 KB
testcase_12 AC 266 ms
11,064 KB
testcase_13 AC 210 ms
10,760 KB
testcase_14 AC 219 ms
10,712 KB
testcase_15 AC 299 ms
11,888 KB
testcase_16 AC 285 ms
11,788 KB
testcase_17 AC 293 ms
11,804 KB
testcase_18 AC 290 ms
11,780 KB
testcase_19 AC 298 ms
12,052 KB
testcase_20 AC 307 ms
12,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long n;
vector<long long> BIT(200020), BIT1(200020);
void add(long long i, long long x) {
	while (i <= n) {
		BIT[i] += x;
		i += i & -i;
	}
}
long long csum(long long i) {
	long long count = 0;
	while (i > 0) {
		count += BIT[i];
		i -= i & -i;
	}
	return count;
}
long long sum(long long l, long long r) {
	return csum(r) - csum(l - 1);
}
void add1(long long i, long long x) {
	while (i <= n) {
		BIT1[i] += x;
		i += i & -i;
	}
}
long long csum1(long long i) {
	long long count = 0;
	while (i > 0) {
		count += BIT1[i];
		i -= i & -i;
	}
	return count;
}
long long sum1(long long l, long long r) {
	return csum1(r) - csum1(l - 1);
}
priority_queue<pair<long long,int>, vector<pair<long long,int>>, greater<pair<long long,int>>>que;
tuple<long long, int, int, int> t[100010];
long long a[100010],ans[100010];
int main() {
	int q;
	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		add(i, a[i]);
		que.push(make_pair(a[i], i));
	}
	for (int i = 0; i < q; i++) {
		int query, l, r;
		long long x;
		cin >> query >> l >> r >> x;
		t[i] = make_tuple(x, l, r, i);
	}
	sort(t, t + q);
	for (int i = 0; i < q; i++) {
		long long x = get<0>(t[i]);
		int y = get<1>(t[i]);
		int z = get<2>(t[i]);
		int in = get<3>(t[i]);
		while (!que.empty() && x >= que.top().first) {
			add(que.top().second, -que.top().first);
			add1(que.top().second, 1);
			que.pop();
		}
		ans[in] = sum(y, z) - (z - y + 1 - sum1(y, z)) * x;
	}
	for (int i = 0; i < q; i++) {
		cout << ans[i] << endl;
	}
}
0