結果
| 問題 | No.1525 Meximum Sum |
| ユーザー |
vjudge1
|
| 提出日時 | 2026-03-17 16:21:05 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 2,000 ms |
| コード長 | 1,652 bytes |
| 記録 | |
| コンパイル時間 | 1,407 ms |
| コンパイル使用メモリ | 211,200 KB |
| 実行使用メモリ | 9,720 KB |
| 最終ジャッジ日時 | 2026-03-17 16:21:08 |
| 合計ジャッジ時間 | 2,052 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define REP(i, a, b) for(int i=(a); i>=(b); --i)
#define umax(x, y) x = max(x, (y))
#define umin(x, y) x = min(x, (y))
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))
#define sz(v) (int)(v).size()
#define ALL(v) (v).begin(),(v).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
const int base = 311;
const ll INF = 1e18;
// Author: rexdino
int n, a[N];
int pos[N];
void solve(){
cin >> n;
FOR(i, 1, n) cin >> a[i], pos[a[i]] = i;
int l = mod, r = 0;
ll ans = 0;
FOR(x, 0, n - 1){
umin(l, pos[x]);
umax(r, pos[x]);
if (l <= pos[x + 1] && pos[x + 1] <= r) continue;
if (pos[x + 1] < l){
ans += 1ll * (x + 1) * (l - (pos[x + 1] + 1) + 1) * (n - r + 1);
// cerr << x + 1 << ": " << 1ll * (l - (pos[x + 1] + 1) + 1) * (n - r + 1) << " ? \n";
} else {
ans += 1ll * (x + 1) * l * (pos[x + 1] - r);
// cerr << x + 1 << ": " << 1ll * l * (pos[x + 1] - r + 1) << ", " << l << " " << pos[x + 1] << " - \n";
}
}
cout << ans;
}
signed main(){
#define NAME "main"
if (fopen(NAME".inp", "r")){
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while(t--) solve();
// cerr << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << "s\n";
return 0;
}
vjudge1