結果

問題 No.1996 <><
ユーザー MasKoaTS
提出日時 2021-12-19 13:59:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,044 bytes
コンパイル時間 4,395 ms
コンパイル使用メモリ 260,568 KB
最終ジャッジ日時 2025-01-27 03:39:59
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 3
other AC * 1 WA * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
using namespace atcoder;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T> >;
template <class T> using BIT = fenwick_tree<T>;
const ll MOD = 998244353;
int main(void) {
int n; cin >> n;
V<ll> a(n); V<ll> b(n);
VV<ll> s(n, V<ll>(2));
rep(i, 0, n) {
cin >> a[i];
s[i] = { a[i],i };
}
sort(all(s));
int cnt = -1; int last = -1;
for (auto& l : s) {
if (l[0] != last) {
cnt += 1;
}
a[l[1]] = cnt;
b[l[1]] = (ll)n - 1 - cnt;
last = l[0];
}
BIT<ll> lbt(n); V<ll> lcnt(n);
BIT<ll> rbt(n); V<ll> rcnt(n);
rep(i, 0, n) {
lbt.add(a[i], 1);
rbt.add(b[(ll)n - 1 - i], 1);
lcnt[i] = lbt.sum(0, a[i]);
rcnt[(ll)n - 1 - i] = rbt.sum(0, b[(ll)n - 1 - i]);
}
BIT<ll> bt(n); ll ans = 0;
rep(i, 0, n) {
bt.add(b[i], lcnt[i]);
ans += bt.sum(0, b[i]) * rcnt[i];
ans %= MOD;
}
cout << ans << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0