結果
| 問題 | No.930 数列圧縮 |
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2019-03-30 03:52:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,274 bytes |
| 記録 | |
| コンパイル時間 | 1,889 ms |
| コンパイル使用メモリ | 172,568 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-07 08:49:59 |
| 合計ジャッジ時間 | 6,518 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 WA * 19 |
ソースコード
#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];
}
}
risujiroh