結果

問題 No.1525 Meximum Sum
ユーザー vjudge1
提出日時 2026-03-17 16:20:15
言語 C++17(gnu拡張)
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 3,960 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,292 ms
コンパイル使用メモリ 203,052 KB
実行使用メモリ 10,020 KB
最終ジャッジ日時 2026-03-17 16:20:21
合計ジャッジ時間 4,608 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from main.cpp:19:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ccomplex:51:4: warning: #warning "<ccomplex> is deprecated in C++17, use <complex> instead" [-Wcpp]
   51 | #  warning "<ccomplex> is deprecated in C++17, use <complex> instead"
      |    ^~~~~~~
In file included from main.cpp:22:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/cstdbool:50:6: warning: #warning "<cstdbool> is deprecated in C++17, remove the #include" [-Wcpp]
   50 | #    warning "<cstdbool> is deprecated in C++17, remove the #include"
      |      ^~~~~~~
In file included from main.cpp:24:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ctgmath:50:6: warning: #warning "<ctgmath> is deprecated in C++17, use <complex> or <cmath> instead" [-Wcpp]
   50 | #    warning "<ctgmath> is deprecated in C++17, use <complex> or <cmath> instead"
      |      ^~~~~~~

ソースコード

diff #
raw source code

///Kiana Kaslana

#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define execute cerr << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << "s"
#define fi first
#define se second
#define el cout <<"\n"
#define pushb push_back
#define pushf push_front
#define popf pop_front
#define popb pop_back
#define MASK(x) (1 << (x))
#define BIT(x, i) ((x) >> (i) & 1)
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Shu "ChinaDog"
///
#define IloveShu signed main()
#define ShiraishiAn while(inp())
#define YoisakiKanade while(KiritaniHaruka--)
#define ever ;;

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<vector<int>> vvi;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;
typedef unsigned long long ull;

const int W = 1e3 + 7;
const int N = 1e6 + 7;
const int S = 1e2 + 7;
const int midd = 1e5;
const int base = 311;
const int LG = 21;
const int mod = 1e9 + 7;
const int prime_mod = 998244353;
const int ascii = 127;
const int alphabet = 26;
const int INF = 2147483647;
const long long INFLL = 4340410370284600380;

template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return 1; }; return 0; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return 1; }; return 0; }

mt19937 rd(time(0));
ll rng(ll l , ll r)
{
    assert(l <= r);
    uniform_int_distribution<ll> d(l , r);
    return d(rd);
}

///MAIN PROGRAMME

int KiritaniHaruka = 1;

int n;
int a[N] , pos[N];

void solve()
{
    ll res = 0;
    int L = pos[0] , R = pos[0];
    for (int x = 1 ; x < n ; ++x)
    {
        int p = pos[x];
        ll cnt = 0;

        if (p < L)
        {
            cnt = 1LL * (L - p) * (n - R);
        } else
        if (p > R)
        {
            cnt = 1LL * (L + 1) * (p - R);
        } else
        {
            cnt = 0;
        }

        res += 1LL * x * cnt;

        L = min(L , p);
        R = max(R , p);
    }

    res += n;

    cout << res;
}

void inp()
{
    cin >> n;
    for (int i = 0 ; i < n ; ++i)
    {
        cin >> a[i];
        pos[a[i]] = i;
    }
}

void file()
{
    if (fopen(Shu".inp" , "r"))
    {
        freopen(Shu".inp" , "r" , stdin);
        freopen(Shu".out" , "w" , stdout);
    }
}

IloveShu
{
    io;
    file();

    //cin >> KiritaniHaruka;

    YoisakiKanade
    {
        inp();
        solve();
    }

//    ShiraishiAn
//    {
//        solve();
//    }
}
0