結果
問題 | No.2250 Split Permutation |
ユーザー |
|
提出日時 | 2023-03-29 18:44:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 125 ms / 3,000 ms |
コード長 | 1,723 bytes |
コンパイル時間 | 1,548 ms |
コンパイル使用メモリ | 170,388 KB |
実行使用メモリ | 6,400 KB |
最終ジャッジ日時 | 2024-09-21 10:22:58 |
合計ジャッジ時間 | 4,984 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
// Problem: No.2250 Split Permutation// Contest: yukicoder// URL: https://yukicoder.me/problems/no/2250// Memory Limit: 512 MB// Time Limit: 3000 ms#include <bits/stdc++.h>#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);#define dbg(x) cout << #x << " = " << (x) << "\n";#define popcount(x) __builtin_popcountll((x))#define all(v) (v).begin(), (v).end()#define pb emplace_back#define x first#define y secondusing namespace std;typedef long long ll;typedef pair<ll, ll> pll;const int inf = 0x3f3f3f3f;const int mod = 998244353;int n;struct BIT {int sz;vector<ll> bit;BIT(int _n) {sz = _n;bit = vector<ll>(sz + 1, 0);}int lowbit(int x) { return x & -x; }void add(int x, ll v) {for (int i = x; i <= sz; i += lowbit(i)) {bit[i] += v;bit[i] %= mod;}}ll ask(int x) {ll ret = 0;for (int i = x; i >= 1; i -= lowbit(i)) {ret = ret + bit[i];ret %= mod;}return ret;}};ll ksm(ll x, ll n) {if (n < 0) n += mod - 1;ll res = 1;while (n) {if (n & 1) res = (res * x) % mod;x = x * x % mod;n >>= 1;}return res;}ll inv(ll x) { return ksm(x, mod - 2); }void solve() {cin >> n;BIT bit1(n), bit2(n);ll ans = 0;for (int i = 1; i <= n; i++) {int x;cin >> x;ans = ans + ksm(2, n - 1) * (bit1.ask(n) - bit1.ask(x)) % mod;ans %= mod;ans = ans - (bit2.ask(n) - bit2.ask(x)) * ksm(2, n - 1) % mod *inv(ksm(2, i)) % mod;ans = (ans + mod) % mod;bit1.add(x, 1);bit2.add(x, ksm(2, i));}cout << ans << "\n";}int main() {fastio;int t = 1;// cin >> t;while (t--) {solve();}return 0;}