結果

問題 No.1079 まお
ユーザー QCFiumQCFium
提出日時 2020-07-04 14:17:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,247 bytes
コンパイル時間 1,904 ms
コンパイル使用メモリ 185,604 KB
実行使用メモリ 28,856 KB
最終ジャッジ日時 2023-10-19 04:15:54
合計ジャッジ時間 14,756 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 327 ms
16,236 KB
testcase_13 AC 386 ms
18,740 KB
testcase_14 AC 505 ms
21,132 KB
testcase_15 AC 571 ms
23,616 KB
testcase_16 AC 650 ms
26,112 KB
testcase_17 WA -
testcase_18 AC 721 ms
25,332 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 786 ms
28,856 KB
testcase_23 AC 782 ms
28,852 KB
testcase_24 AC 797 ms
28,852 KB
testcase_25 AC 824 ms
28,852 KB
testcase_26 AC 831 ms
28,852 KB
testcase_27 AC 25 ms
4,348 KB
testcase_28 AC 326 ms
17,920 KB
testcase_29 AC 470 ms
25,728 KB
testcase_30 AC 465 ms
25,728 KB
testcase_31 AC 37 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::vector<int> a;
int k;

int64_t res = 0;
void solve(int l, int r) {
	if (r - l == 1) {
		if (a[l] * 2 == k) res += 1;
		return;
	}
	int m = l + ((r - l) >> 1);
	int min = 1000000000;
	int cnt = 0;
	std::map<int, std::pair<int, int64_t> > right; // val : {cnt, index sum}
	std::map<std::pair<int, int>, std::pair<int64_t, int> > right_special; // {val, min} : {cnt, index sum}
	for (int i = m; i < r; i++) {
		if (min > a[i]) min = a[i], cnt = 1;
		else if (min == a[i]) cnt++;
		if (cnt > 1) continue;
		auto &r0 = right[a[i]];
		r0.first++;
		r0.second += i;
		auto &r1 = right_special[{a[i], min}];
		r1.first++;
		r1.second += i;
	}
	min = 1000000000;
	cnt = 0;
	for (int i = m - 1; i >= l; i--) {
		if (min > a[i]) min = a[i], cnt = 1;
		else if (min == a[i]) cnt++;
		if (cnt > 1) continue;
		auto &r0 = right[k - a[i]];
		auto &r1 = right_special[{k - a[i], min}];
		int cnt = r0.first - r1.first;
		int64_t sum = r0.second - r1.second;
		res += sum;
		res -= (int64_t) cnt * (i - 1);
	}
	solve(l, m);
	solve(m, r);
}


int main() {
	int n = ri();
	k = ri();
	a.resize(n);
	for (auto &i : a) i = ri();
	solve(0, n);
	printf("%" PRId64 "\n", res);
	return 0;
}
0