結果

問題 No.1525 Meximum Sum
ユーザー 沙耶花
提出日時 2021-05-30 11:28:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 489 bytes
コンパイル時間 6,761 ms
コンパイル使用メモリ 249,488 KB
最終ジャッジ日時 2025-01-21 20:46:15
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 100000000000000000

int main(){
	
	int N;
	cin>>N;
	
	vector<long long> A(N);
	rep(i,N){
		int a;
		cin>>a;
		A[a] = i;
	}
	
	long long ans = 0LL;
	long long r = 0,l = N;
	
	rep(i,N){
		r = max(r,A[i]+1);
		l = min(l,A[i]);
		ans += (l+1) * (N-r+1);
	}
	
	cout<<ans<<endl;
	
	return 0;
}
0