結果
| 問題 |
No.1733 Sum of Sorted Subarrays
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2021-11-07 15:23:51 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,823 ms / 3,000 ms |
| コード長 | 1,269 bytes |
| コンパイル時間 | 4,478 ms |
| コンパイル使用メモリ | 260,404 KB |
| 最終ジャッジ日時 | 2025-01-25 14:34:37 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001
mint op(mint a,mint b){
return a+b;
}
mint e(){
return 0;
}
mint mapping(mint a,mint b){
return a*b;
}
mint composition(mint a,mint b){
return a*b;
}
mint id(){
return 1;
}
vector<int> a;
int n;
mint ans = 0;
void dfs(int l,int r){
//cout<<l<<','<<r<<endl;
if(l==r)return;
if(r-l==1){
ans += a[l];
return;
}
int m = (l+r)/2;
lazy_segtree<mint,op,e,mint,mapping,composition,id> R(r-m), L(m-l+1);
rep(i,r-m)R.set(i,1);
rep(i,m-l+1)L.set(i,1);
vector<pair<int,int>> v;
for(int i=l;i<r;i++){
v.emplace_back(a[i],i);
}
sort(v.begin(),v.end());
rep(i,v.size()){
mint value = v[i].first;
int ind = v[i].second;
if(ind < m){
mint temp = value;
temp *= L.prod(0,ind-l+1);
temp *= R.all_prod();
ans += temp;
L.apply(0,ind-l+1,2);
}
else{
mint temp = value;
temp *= L.all_prod();
temp *= R.prod(ind-m,r-m);
ans += temp;
R.apply(ind-m,r-m,2);
}
}
dfs(l,m);
dfs(m+1,r);
}
int main(){
cin>>n;
a.resize(n);
rep(i,n)cin>>a[i];
dfs(0,n);
cout<<ans.val()<<endl;
return 0;
}
沙耶花