結果

問題 No.1687 What the Heck?
ユーザー icchiposticchipost
提出日時 2021-10-17 18:11:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 590 bytes
コンパイル時間 1,819 ms
コンパイル使用メモリ 174,908 KB
実行使用メモリ 13,368 KB
最終ジャッジ日時 2023-10-17 22:30:51
合計ジャッジ時間 5,748 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 77 ms
7,032 KB
testcase_08 AC 118 ms
8,404 KB
testcase_09 WA -
testcase_10 AC 46 ms
5,864 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 334 ms
13,368 KB
testcase_14 AC 337 ms
13,368 KB
testcase_15 AC 334 ms
13,368 KB
testcase_16 AC 306 ms
13,368 KB
testcase_17 AC 13 ms
4,420 KB
testcase_18 AC 325 ms
13,368 KB
testcase_19 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  int n;
  cin >> n;
  set<int> st;
  vector<int> a(n + 1);
  rep(i, n) {
    cin >> a[i + 1];
    st.insert(a[i + 1]);
  }
  ll ans = 0;
  for (int i = n; i > 0; i--) {
    auto itr = st.upper_bound(a[i]);
    if (itr == st.end()) itr = st.lower_bound(a[i]);
    if (itr == st.end()) itr = st.lower_bound(0);
    if (*itr > a[i]) ans += i;
    if (*itr < a[i]) ans -= i;
    st.erase(*itr);
  }
  cout << ans << endl;
  return 0;
}
0