結果
問題 | No.1996 <>< |
ユーザー |
![]() |
提出日時 | 2021-12-19 18:32:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,008 bytes |
コンパイル時間 | 3,950 ms |
コンパイル使用メモリ | 257,660 KB |
最終ジャッジ日時 | 2025-01-27 03:55:07 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 3 |
other | AC * 1 WA * 28 |
ソースコード
#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()#define lb(a, x) lower_bound(all(a), x) - a.begin()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);rep(i, 0, n) {cin >> a[i];}V<ll> s = a; sort(all(s));s.erase(unique(all(s)), s.end());rep(i, 0, a.size()) {a[i] = lb(s, a[i]);b[i] = s.size() - 1 - a[i];}BIT<ll> lbt(n); V<ll> lcnt(n);BIT<ll> rbt(n); V<ll> rcnt(n);rep(i, 0, n) {int k = n - 1 - i;lbt.add(a[i], 1);rbt.add(b[k], 1);lcnt[i] = lbt.sum(0, a[i]);rcnt[k] = rbt.sum(0, b[k]);}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;}