結果
問題 | No.2250 Split Permutation |
ユーザー |
|
提出日時 | 2023-03-17 22:25:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 66 ms / 3,000 ms |
コード長 | 1,118 bytes |
コンパイル時間 | 2,872 ms |
コンパイル使用メモリ | 156,300 KB |
最終ジャッジ日時 | 2025-02-11 13:33:00 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
#include<iostream>#include<vector>#include<algorithm>#include<atcoder/all>using namespace std;using namespace atcoder;using ll=long long;using mint=modint998244353;#define rep(i,n) for(int i=0;i<n;i++)#define rrep(i,n) for(int i=(n)-1;i>=0;i--)#define all(v) v.begin(),v.end()#define rall(v) v.rbegin(),v.rend()template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int n;cin>>n;vector<int>p(n);vector<pair<int,int>>vp;rep(i,n){cin>>p[i];p[i]--;vp.push_back(make_pair(p[i],i));}sort(all(vp));fenwick_tree<int>C(n);fenwick_tree<mint>fw(n);mint ans=0;vector<mint>P(n);P[0]=1;rep(i,n-1){P[i+1]=P[i]*2;}for(auto[ignore,i]:vp){int c=C.sum(i,n);mint s=fw.sum(i,n);s*=P[i];ans+=c*P[n-1]-s;fw.add(i,P[n-1-i]);C.add(i,1);}cout<<ans.val()<<"\n";}