結果

問題 No.1525 Meximum Sum
ユーザー huan han
提出日時 2025-08-12 17:43:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 659 bytes
コンパイル時間 778 ms
コンパイル使用メモリ 78,764 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-12 17:43:06
合計ジャッジ時間 4,122 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)


int main(){
  int N; cin >> N;
  vector<int> A(N); rep(i,N) cin >> A[i];
  vector<int> P(N);
  rep(i,N) P[A[i]] = i;
  vector<int> L = P;
  vector<int> R = P;
  rep(i,N-1) L[i+1] = min(L[i],L[i+1]);
  rep(i,N-1) R[i+1] = max(R[i],R[i+1]);
  ll ans = 0;
  rep(i,N){
    ans += 1ll * (L[i]+1) * (N-R[i]);
  }
  cout << ans << "\n";
  return 0;
}



struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_instance;


0