結果

問題 No.930 数列圧縮
ユーザー risujirohrisujiroh
提出日時 2019-03-30 03:52:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,274 bytes
コンパイル時間 1,869 ms
コンパイル使用メモリ 169,476 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 23:32:06
合計ジャッジ時間 6,741 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 7 ms
5,376 KB
testcase_14 AC 8 ms
5,376 KB
testcase_15 AC 24 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
5,376 KB
testcase_23 WA -
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<class T> struct FenwickTree {
  const int n;
  V<T> t;
  FenwickTree(int n) : n(n), t(n + 1) {}
  void add(int i, T x) { for (++i; i <= n; i += i & -i) t[i] += x; }
  T sum(int i) const {
    T s = 0;
    for (; i; i -= i & -i) s += t[i];
    return s;
  }
  T sum(int l, int r) const { return sum(r) - sum(l); }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (auto&& e : a) cin >> e, --e;
  if (a[0] > a.back()) {
    cout << "No" << '\n';
    return 0;
  }
  cout << "Yes" << '\n';
  V<> lc(n), rc(n);
  {
    FenwickTree<int> ft(n);
    for (int i = 0; i < n; ++i) {
      lc[i] = ft.sum(a[i]);
      ft.add(a[i], 1);
    }
  }
  {
    FenwickTree<int> ft(n);
    for (int i = n - 1; i >= 0; --i) {
      rc[i] = ft.sum(a[i], n);
      ft.add(a[i], 1);
    }
  }
  V<> b(n);
  for (int i = 0; i < n; ++i) {
    b[i] = lc[i] + rc[i];
  }
  V<> idx(n);
  iota(begin(idx), end(idx), 0);
  sort(begin(idx), end(idx), [&](int i, int j) { return b[i] < b[j]; });
  for (int i = 0; i < n - 1; ++i) {
    cout << a[idx[i]] + 1 << " \n"[i == n - 2];
  }
}
0