結果

問題 No.1525 Meximum Sum
ユーザー vjudge1
提出日時 2026-03-17 16:55:08
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,585 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,346 ms
コンパイル使用メモリ 331,504 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2026-03-17 16:55:12
合計ジャッジ時間 2,890 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
bool memory1;

typedef long long ll;
typedef unsigned long long ull;
typedef double dbe;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vii;

#define openFile(name) freopen((name ".inp"), "r", stdin), freopen((name ".out"), "w", stdout)
#define FOR(i, a, b, x) for (ll i = (a); i <= (b); i += (x))
#define ROF(i, a, b, x) for (ll i = (a); i >= (b); i += (x))
#define fi first
#define se second
#define MASK(x) (1LL << (x))
#define getBit(mask, i) (((mask) >> (i)) & 1LL)
#define BitOn(mask) (__builtin_popcountll(mask))

const int maxN = 2e5 + 5;
//const ll maxBit = MASK(8) + 2;
const ll LOG = 20;
const ll INF18 = 1e18;
const int INF9 = 1e9;
//const ll INF3f = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9 + 7;

//////////////////////////////////////////////
/////////////////nhan0123456//////////////////
//////////////////////////////////////////////

ll n;
ll a[maxN];
ll p[maxN];


ll Solve() {
    FOR (i, 1, n, 1) p[a[i]] = i;
    ll L = p[0], R = p[0];
    ll ans = 0;
    FOR (i, 1, n, 1) {
        ans += L * (n - R + 1);
        L = min(L, p[i]);
        R = max(R, p[i]);
    }
    return ans;
}

void input() {
    cin >> n;
    FOR (i, 1, n, 1) cin >> a[i];
    cout << Solve();
}

int main() {
    //openFile("temp");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    input();

    //bool memory2;
    //cerr << "\n\n\nTime: "<< 1000.0 * clock() / CLOCKS_PER_SEC << " ms";
    //cerr << "\n\n\nMemory: "<< abs(&memory1 - &memory2) * 1.0 / MASK(20) <<" MB";

    return 0;
}
0