結果

問題 No.877 Range ReLU Query
ユーザー ianCKianCK
提出日時 2019-12-07 06:53:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,577 bytes
コンパイル時間 511 ms
コンパイル使用メモリ 43,084 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 22:18:38
合計ジャッジ時間 2,751 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 3 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,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 84 ms
6,944 KB
testcase_12 AC 73 ms
6,944 KB
testcase_13 AC 58 ms
6,944 KB
testcase_14 AC 58 ms
6,944 KB
testcase_15 AC 83 ms
6,940 KB
testcase_16 AC 81 ms
6,940 KB
testcase_17 AC 82 ms
6,940 KB
testcase_18 AC 79 ms
6,940 KB
testcase_19 AC 77 ms
6,944 KB
testcase_20 AC 80 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |         scanf("%d%d", &n, &q);
      |         ~~~~~^~~~~~~~~~~~~~~~
main.cpp:46:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |         for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
      |                                      ~~~~~^~~~~~~~~~~~~
main.cpp:47:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |         for (int i = 1; i <= q; i++) scanf("%d%d%d%d", &k, &query[i].l, &query[i].r, &query[i].x);
      |                                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <utility>
using namespace std;
#define F first
#define S second
constexpr int kN = int(1E5 + 10);
typedef long long int ll;

struct Query {
	int l, r, x, id;
};

struct BIT {
	ll val[kN];
	void init() {memset(val, 0, sizeof(val));}
	void add(int pos, int x) {
		while (pos < kN) {
			val[pos] += x;
			pos += pos & -pos;
		}
		return ;
	}
	ll ask(int pos) {
		ll ans = 0;
		while (pos) {
			ans += val[pos];
			pos ^= pos & -pos;
		}
		return ans;
	}
};

bool cmp(Query a, Query b) {return a.x < b.x;}

BIT cnt, tot;
int a[kN];
ll ans[kN];
pair<int, int> na[kN];
Query query[kN];

int main() {
	int n, q, k, now = 1;
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= q; i++) scanf("%d%d%d%d", &k, &query[i].l, &query[i].r, &query[i].x);
	for (int i = 1; i <= q; i++) query[i].id = i;
	cnt.init();
	tot.init();
	for (int i = 1; i <= n; i++) tot.add(i, a[i]);
	for (int i = 1; i <= n; i++) cnt.add(i, 1);
	for (int i = 1; i <= n; i++) na[i] = {a[i], i};
	sort(na + 1, na + n + 1);
	sort(query + 1, query + q + 1, cmp);
	for (int i = 1; i <= q; i++) {
		while (now <= n) {
			if (na[now].F < query[i].x) {
				cnt.add(na[now].S, -1);
				tot.add(na[now].S, -na[now].F);
				now++;
			}
			else break;
		}
		ans[query[i].id] = tot.ask(query[i].r) - tot.ask(query[i].l - 1) - (cnt.ask(query[i].r) - cnt.ask(query[i].l - 1)) * query[i].x;
	}
	for (int i = 1; i <= q; i++) printf("%lld\n", ans[i]);
}
0