結果

問題 No.877 Range ReLU Query
ユーザー snrnsidysnrnsidy
提出日時 2021-05-09 03:24:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 1,485 bytes
コンパイル時間 2,515 ms
コンパイル使用メモリ 210,196 KB
実行使用メモリ 8,960 KB
最終ジャッジ日時 2024-04-25 22:30:51
合計ジャッジ時間 4,974 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 93 ms
8,088 KB
testcase_12 AC 85 ms
7,804 KB
testcase_13 AC 67 ms
6,972 KB
testcase_14 AC 70 ms
6,944 KB
testcase_15 AC 100 ms
8,664 KB
testcase_16 AC 96 ms
8,496 KB
testcase_17 AC 98 ms
8,656 KB
testcase_18 AC 99 ms
8,548 KB
testcase_19 AC 93 ms
8,860 KB
testcase_20 AC 97 ms
8,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

long long int tree[2][100005];
long long int sum(int i,int idx)
{
	long long int ans = 0;
	while (i > 0)
	{
		ans += tree[idx][i];
		i -= (i & -i);
	}
	return ans;
}

void update(int i, long long int diff,int idx)
{
	while (i < 100005)
	{
		tree[idx][i] += diff;
		i += (i & (-i));
	}
}

long long int res[100005];

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	priority_queue <pair<long long int, int>> pque;
	vector <pair<pair<int,int>, pair<int, int>>> query;
	int n, q, a;
	
	cin >> n >> q;

	for (int i = 1; i <= n; i++)
	{
		cin >> a;
		pque.push(make_pair(a, i));
	}

	for (int i = 0; i < q; i++)
	{
		int x,l, r;
		cin >> x >> l >> r >> a;
		query.push_back(make_pair(make_pair(a,i), make_pair(l, r)));
	}

	sort(query.rbegin(), query.rend());

	for (int i = 0; i < q; i++)
	{
		while (!pque.empty())
		{
			if (pque.top().first < query[i].first.first)
			{
				break;
			}
			//cout << pque.top().first << ' ' << pque.top().second << ' ' << query[i].first.first << '\n';
			update(pque.top().second, pque.top().first, 0);
			update(pque.top().second, 1, 1);
			pque.pop();
		}
		int l = query[i].second.first;
		int r = query[i].second.second;
		int idx = query[i].first.second;
		long long int val = sum(r, 0) - sum(l - 1, 0);
		long long int num = sum(r, 1) - sum(l - 1, 1);
		val -= (num * query[i].first.first);
		res[idx] = val;
	}

	for (int i = 0; i < q; i++)
	{
		cout << res[i] << '\n';
	}

	return 0;
}
0