結果

問題 No.1687 What the Heck?
ユーザー icchipost
提出日時 2021-10-17 18:11:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 590 bytes
コンパイル時間 1,346 ms
コンパイル使用メモリ 174,096 KB
実行使用メモリ 13,440 KB
最終ジャッジ日時 2024-09-17 19:43:24
合計ジャッジ時間 4,499 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14 WA * 4
権限があれば一括ダウンロードができます

ソースコード

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