結果

問題 No.1435 Mmm......
ユーザー trineutrontrineutron
提出日時 2021-03-20 00:43:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 666 ms / 2,000 ms
コード長 1,477 bytes
コンパイル時間 2,501 ms
コンパイル使用メモリ 215,392 KB
実行使用メモリ 22,784 KB
最終ジャッジ日時 2024-04-29 20:37:12
合計ジャッジ時間 9,580 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 155 ms
5,376 KB
testcase_07 AC 188 ms
5,376 KB
testcase_08 AC 221 ms
5,376 KB
testcase_09 AC 200 ms
5,376 KB
testcase_10 AC 175 ms
5,376 KB
testcase_11 AC 173 ms
5,376 KB
testcase_12 AC 161 ms
5,376 KB
testcase_13 AC 157 ms
5,376 KB
testcase_14 AC 118 ms
5,376 KB
testcase_15 AC 227 ms
5,376 KB
testcase_16 AC 187 ms
5,376 KB
testcase_17 AC 133 ms
5,376 KB
testcase_18 AC 230 ms
5,376 KB
testcase_19 AC 169 ms
5,376 KB
testcase_20 AC 208 ms
5,376 KB
testcase_21 AC 90 ms
5,736 KB
testcase_22 AC 59 ms
5,740 KB
testcase_23 AC 658 ms
22,784 KB
testcase_24 AC 652 ms
22,784 KB
testcase_25 AC 666 ms
22,784 KB
testcase_26 AC 663 ms
22,784 KB
testcase_27 AC 654 ms
22,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    priority_queue<int> q;
    priority_queue<int, vector<int>, greater<int>> r;
    map<int, int> removed_q, removed_r;
    int bound = 0;
    int64_t ans = 0;
    for (int i = 0; i < n; i++)
    {
        while (bound < n and bound - i < 2)
        {
            q.push(a.at(bound));
            r.push(a.at(bound));
            bound++;
        }
        while (bound <= n)
        {
            while (removed_q[q.top()])
            {
                removed_q[q.top()]--;
                q.pop();
            }
            int mmax = q.top();
            while (removed_r[r.top()])
            {
                removed_r[r.top()]--;
                r.pop();
            }
            int m0 = r.top();
            r.pop();
            while (removed_r[r.top()])
            {
                removed_r[r.top()]--;
                r.pop();
            }
            int m1 = r.top();
            r.push(m0);
            if (mmax > m0 + m1)
            {
                break;
            }
            if (bound < n)
            {
                q.push(a.at(bound));
                r.push(a.at(bound));
            }
            bound++;
        }
        removed_q[a.at(i)]++;
        removed_r[a.at(i)]++;
        ans += max(0, bound - i - 2);
    }
    cout << ans << endl;
    return 0;
}
0