結果

問題 No.2250 Split Permutation
ユーザー publfl2publfl2
提出日時 2023-03-17 22:21:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 328 ms / 3,000 ms
コード長 1,386 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 50,740 KB
実行使用メモリ 15,892 KB
最終ジャッジ日時 2023-10-18 15:17:28
合計ジャッジ時間 5,411 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,260 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
7,332 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
7,332 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 3 ms
11,348 KB
testcase_10 AC 3 ms
7,260 KB
testcase_11 AC 3 ms
7,332 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 3 ms
7,332 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 3 ms
11,348 KB
testcase_16 AC 4 ms
11,348 KB
testcase_17 AC 2 ms
7,260 KB
testcase_18 AC 320 ms
15,892 KB
testcase_19 AC 321 ms
11,392 KB
testcase_20 AC 280 ms
10,340 KB
testcase_21 AC 166 ms
9,800 KB
testcase_22 AC 260 ms
9,736 KB
testcase_23 AC 45 ms
4,596 KB
testcase_24 AC 247 ms
10,860 KB
testcase_25 AC 320 ms
14,064 KB
testcase_26 AC 120 ms
6,528 KB
testcase_27 AC 31 ms
4,348 KB
testcase_28 AC 59 ms
4,980 KB
testcase_29 AC 328 ms
12,132 KB
testcase_30 AC 64 ms
5,120 KB
testcase_31 AC 17 ms
4,348 KB
testcase_32 AC 86 ms
5,568 KB
testcase_33 AC 201 ms
8,348 KB
testcase_34 AC 46 ms
4,608 KB
testcase_35 AC 138 ms
9,284 KB
testcase_36 AC 83 ms
8,556 KB
testcase_37 AC 328 ms
15,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#define MOD 998244353

long long int power(long long int a, long long int b)
{
	long long int ans = 1;
	long long int k = a;
	while(b)
	{
		if(b%2==1) ans*=k, ans%=MOD;
		b/=2;
		k*=k, k%=MOD;
	}
	return ans;
}
long long int inv(long long int k)
{
	return power(k,MOD-2);
}

struct segTree{
	long long int value[800010];
	void setValue(int ind, long long int val, int l=1, int r=200000, int v=1)
	{
		if(l==r) value[v] = val;
		else
		{
			int h = (l+r)/2;
			if(ind<=h) setValue(ind,val,l,h,2*v);
			else setValue(ind,val,h+1,r,2*v+1);
			value[v] = (value[2*v]+value[2*v+1])%MOD;
		}
	}
	long long int getSum(int L, int R, int l=1, int r=200000, int v=1)
	{
		if(L<=l&&r<=R) return value[v];
		else if(r<L) return 0;
		else if(R<l) return 0;
		else
		{
			int h = (l+r)/2;
			long long int s1 = getSum(L,R,l,h,2*v);
			long long int s2 = getSum(L,R,h+1,r,2*v+1);
			return (s1+s2)%MOD;
		}
	}
}T1,T2;

int x[200010];
int main()
{
	int a;
	scanf("%d",&a);
	for(int i=1;i<=a;i++) scanf("%d",&x[i]);
	long long int ans = 0;
	for(int i=1;i<=a;i++)
	{
		long long int c1 = T1.getSum(x[i]+1,a);
		long long int c2 = T2.getSum(x[i]+1,a);
		c2 *= inv(power(2,i)), c2 %= MOD;
		long long int val = (c1-c2+MOD)%MOD;
		val *= power(2,a-1), val %= MOD;
		ans += val, ans %= MOD;
		T1.setValue(x[i],1);
		T2.setValue(x[i],power(2,i));
	}
	printf("%lld",ans);
}
0