結果

問題 No.1525 Meximum Sum
ユーザー ooaiu
提出日時 2025-02-14 09:33:20
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 655 bytes
コンパイル時間 4,641 ms
コンパイル使用メモリ 274,864 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-02-14 09:33:28
合計ジャッジ時間 7,096 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) (void(0))
#endif
void run_case();
int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int T = 1;
	// cin >> T;
	while (T--) run_case();
	return 0;
}
void run_case() {
	int N;
	cin >> N;
	vector<int> A(N);
	for(auto&x: A) cin >> x;
	vector<int> pos(N);
	for(int i = 0; i < N; i++) pos[A[i]] = i;
	int l = N, r = 0;
	ll ans = 0;
	for(int k = 0; k < N; k++) {
		l = min(l, pos[k]);
		r = max(r, pos[k]);
		ll L = l, R = N - r - 1;
		debug(L, R);
		ans += (L + 1) * (R + 1);
	}
	cout << ans << "\n";
}	
0