結果

問題 No.2055 12x34...
ユーザー pengin_2000pengin_2000
提出日時 2022-08-21 13:07:30
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,709 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 31,360 KB
実行使用メモリ 12,848 KB
最終ジャッジ日時 2024-04-18 12:49:02
合計ジャッジ時間 5,067 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
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 63 ms
7,552 KB
testcase_13 AC 122 ms
11,008 KB
testcase_14 AC 43 ms
5,632 KB
testcase_15 AC 44 ms
5,760 KB
testcase_16 AC 137 ms
11,520 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
long long int h[400005], l;
int comp_h(long long int a, long long int b)
{
	if (h[a] > h[b])
		return 1;
	else
		return -1;
}
void swap_h(long long int a, long long int b)
{
	long long int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
void push(long long int ne)
{
	h[l] = ne;
	long long int p = l;
	l++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
long long int pop()
{
	l--;
	swap_h(0, l);
	long long int p = 0;
	for (;;)
	{
		if (2 * p + 2 < l)
		{
			if (comp_h(2 * p + 1, 2 * p + 2) > 0)
			{
				if (comp_h(p, 2 * p + 2) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < l)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[l];
}
long long int n;
long long int s[400005];
long long int fined_idx(long long int v)
{
	long long int min, mid, max;
	min = -1;
	max = 2 * n;
	while (max - min > 1)
	{
		mid = (max + min) / 2;
		if (s[mid] < v)
			min = mid;
		else
			max = mid;
	}
	return max;
}
long long int a[200005];
long long int dp[400005];
int main()
{
	scanf("%lld", &n);
	long long int i;
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	long long int p = 998244353;
	l = 0;
	for (i = 0; i < n; i++)
		push(a[i]);
	for (i = 0; i < n; i++)
		push(a[i] - 1);
	for (i = 0; i < 2 * n; i++)
		s[i] = pop();
	for (i = 0; i < 2 * n; i++)
		dp[i] = 0;
	long long int ans = 0;
	for (i = 0; i < n; i++)
	{
		ans += dp[fined_idx(a[i] - 1)];
		dp[fined_idx(a[i])] += dp[fined_idx(a[i] - 1)] + 1;
	}
	printf("%lld\n", ans);
	return 0;
}
0