結果

問題 No.1300 Sum of Inversions
ユーザー tails
提出日時 2020-11-30 10:59:16
言語 cLay
(20241019-1)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 407 bytes
コンパイル時間 6,805 ms
コンパイル使用メモリ 219,332 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2024-07-05 14:48:12
合計ジャッジ時間 10,689 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#define MD 998244353

struct S {
	Mint a,b,c,d;
	S(int){}
	S(Mint a,Mint b,Mint c,Mint d):a(a),b(b),c(c),d(d){}
	void operator+=(S const& s){
		a+=s.a;
		b+=s.b;
		c+=s.c;
		d+=s.d;
	}
};

int a[2d5],c[2d5];
{
	fenwick<S>f;
	f.walloc(2d5,1);
	Mint sum=0;
	ll @n;
	rd(a(n));
	coordcomp(n,a,c);
	rep(i,n){
		S s=f.get(n-c[i]-1);
		sum+=a[i]*s.b+s.d;
		f.add(n-c[i],S(1,s.a,a[i],a[i]*s.a+s.c));
	}
	wt(sum);
}
0