結果

問題 No.1687 What the Heck?
ユーザー ぷらぷら
提出日時 2021-09-24 21:31:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 571 bytes
コンパイル時間 2,093 ms
コンパイル使用メモリ 206,372 KB
実行使用メモリ 13,156 KB
最終ジャッジ日時 2023-09-18 20:45:15
合計ジャッジ時間 5,328 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 75 ms
6,856 KB
testcase_08 AC 117 ms
8,072 KB
testcase_09 WA -
testcase_10 AC 46 ms
5,536 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 293 ms
13,052 KB
testcase_14 AC 290 ms
13,108 KB
testcase_15 AC 298 ms
13,156 KB
testcase_16 AC 290 ms
13,112 KB
testcase_17 AC 13 ms
4,376 KB
testcase_18 AC 290 ms
13,048 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int N;
    cin >> N;
    vector<int>P(N);
    set<int>st;
    for(int i = 0; i < N; i++) {
        cin >> P[i];
        st.insert(i+1);
    }
    long long sum = 0;
    for(int i = N-1; i >= 0; i--) {
        if(st.lower_bound(P[i]) == st.end()) {
            sum -= i+1;
        }
        else if(st.upper_bound(P[i]) != st.end()) {
            sum += i+1;
            st.erase(st.upper_bound(P[i]));
        }
        else {
            st.erase(st.find(P[i]));
        }
    }
    cout << sum << endl;
}
0