結果
| 問題 | No.2250 Split Permutation | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-03-21 01:31:29 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 114 ms / 3,000 ms | 
| コード長 | 2,757 bytes | 
| コンパイル時間 | 2,134 ms | 
| コンパイル使用メモリ | 197,652 KB | 
| 最終ジャッジ日時 | 2025-02-11 15:44:34 | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 35 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<unsigned mod, unsigned prim = 0> struct ModInt {
    int64_t x;
    ModInt() : x(0) {}
    ModInt(int64_t a) : x(a >= 0 ? a % mod : (a % mod + mod) % mod) {}
    inline unsigned getmod() const { return mod; }
    inline ModInt getprim() const { return ModInt(prim); }
    inline ModInt &operator+=(const ModInt &rhs) {
        x = x + rhs.x < mod ? x + rhs.x : x + rhs.x - mod;
        return *this; 
    }
    inline ModInt &operator-=(const ModInt &rhs) {
        x = x - rhs.x < 0 ? mod + x - rhs.x : x - rhs.x;
        return *this; 
    }
    inline ModInt &operator*=(const ModInt &rhs) {
        x = x * rhs.x % mod;
        return *this;
    }
    inline ModInt &operator/=(const ModInt &rhs) {
        return *this *= rhs.inv();
    }
    inline ModInt modpow(uint64_t n) {
        if (x == 0) return x;
        ModInt ret(1), mul(x); 
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    inline ModInt inv() const { return ModInt(x).modpow(mod - 2); }
    inline ModInt operator-() const { return ModInt(-x); }
    inline ModInt operator+(const ModInt &rhs) const { return ModInt(x) += rhs; }
    inline ModInt operator-(const ModInt &rhs) const { return ModInt(x) -= rhs; }
    inline ModInt operator*(const ModInt &rhs) const { return ModInt(x) *= rhs; }
    inline ModInt operator/(const ModInt &rhs) const { return ModInt(x) /= rhs; }
    inline bool operator==(const ModInt &rhs) const { return x == rhs.x; }
    inline bool operator!=(const ModInt &rhs) const { return x != rhs.x; }
    friend ostream &operator<<(ostream &os, const ModInt &rhs) { return os << rhs.x; }
    friend istream &operator>>(istream &is, ModInt &rhs) { int64_t i; is >> i; rhs = ModInt(i); return is; }
};
// zero-based numbering
template<class T> struct Fenwick {
    vector<T> bit; int N;
    Fenwick(int n) : N(n) { bit.assign(n+1, 0); }
    // add w to a
    void add(int a, T w) {
        for (int x = ++a; x <= N; x += x & -x) bit[x] += w;
    }
    // sum [0, a)
    T sum(int a) {
        T ret = 0;
        for (int x = a; x > 0; x -= x & -x) ret += bit[x];
        return ret;
    }
    // sum [a, b)
    T sum(int a, int b) { return sum(b) - sum(a); }
};
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    using mod = ModInt<998244353>;
    Fenwick<mod> f(N), g(N);
    mod c = mod(2).modpow(N - 1);
    mod sum = 0;
    for (int i = 0; i < N; i++) {
        int p; cin >> p; p--;
        mod d = mod(2).modpow(i);
        f.add(p, 1);
        g.add(p, d);
        sum += c * (f.sum(p + 1, N) - g.sum(p + 1, N) / d);
    }
    cout << sum << '\n';
    return 0;
}
            
            
            
        