結果
| 問題 |
No.2950 Max Min Product
|
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2024-10-25 22:18:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,544 bytes |
| コンパイル時間 | 4,515 ms |
| コンパイル使用メモリ | 262,892 KB |
| 最終ジャッジ日時 | 2025-02-24 23:35:48 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 RE * 1 |
ソースコード
/**
author: shobonvip
created: 2024.10.25 22:03:11
**/
#include<bits/stdc++.h>
using namespace std;
//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/
/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/
typedef long long ll;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
template <typename T> bool chmin(T &a, const T &b) {
if (a <= b) return false;
a = b;
return true;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a >= b) return false;
a = b;
return true;
}
template <typename T> T max(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
return ret;
}
template <typename T> T min(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
return ret;
}
template <typename T> T sum(vector<T> &a){
T ret = 0;
for (int i=0; i<(int)a.size(); i++) ret += a[i];
return ret;
}
struct S{
mint val;
ll len;
};
struct F{
mint b;
mint c;
};
S op(S x, S y){
return {x.val + y.val, x.len + y.len};
}
S e(){
return {0, 0};
}
S mapping(F f, S x){
return {f.b * x.val + f.c * x.len, x.len};
}
F composition(F g, F f){
return {f.b * g.b, f.c * g.b + g.c};
}
F id(){
return {1, 0};
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
vector<ll> a(n);
rep(i,0,n){
cin >> a[i];
}
vector<int> max_st = {(int)1e9+20};
vector<int> max_ind = {0};
vector<int> min_st = {-1};
vector<int> min_ind = {0};
set<pair<int,int>> bad_points;
lazy_segtree<S,op,e,F,mapping,composition,id> seg(vector<S>(n,S{1,1}));
mint ans = 0;
rep(i,0,n){
{
int now = i;
while(a[i] >= max_st.back()) {
int val = max_st.back();
max_ind.pop_back();
int tar = max_ind.back();
seg.apply(tar, now, F{mint(val).inv(), 0});
max_st.pop_back();
now = tar;
}
seg.apply(now, i+1, F{a[i], 0});
max_st.push_back(a[i]);
max_ind.push_back(i+1);
}
{
int now = i;
while(a[i] <= min_st.back()) {
int val = min_st.back();
min_ind.pop_back();
int tar = min_ind.back();
seg.apply(tar, now, F{mint(val).inv(), 0});
min_st.pop_back();
now = tar;
}
seg.apply(now, i+1, F{a[i], 0});
min_st.push_back(a[i]);
min_ind.push_back(i+1);
}
ans += seg.prod(0, i+1).val;
//cout << ans.val() << '\n';
}
cout << ans.val() << '\n';
}
shobonvip