結果

問題 No.1888 Odd Insertion
ユーザー 👑 colognecologne
提出日時 2022-03-25 23:50:11
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,741 bytes
コンパイル時間 4,030 ms
コンパイル使用メモリ 284,560 KB
実行使用メモリ 8,720 KB
最終ジャッジ日時 2024-04-22 08:54:10
合計ジャッジ時間 14,728 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,940 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 75 ms
6,940 KB
testcase_07 AC 74 ms
6,944 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 72 ms
6,944 KB
testcase_17 WA -
testcase_18 AC 72 ms
6,944 KB
testcase_19 AC 73 ms
6,940 KB
testcase_20 AC 73 ms
6,940 KB
testcase_21 AC 72 ms
6,940 KB
testcase_22 AC 72 ms
6,940 KB
testcase_23 AC 72 ms
6,940 KB
testcase_24 AC 72 ms
6,944 KB
testcase_25 AC 71 ms
6,944 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 72 ms
7,692 KB
testcase_30 AC 72 ms
6,940 KB
testcase_31 AC 69 ms
6,940 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using T = atcoder::fenwick_tree<int>;

int main()
{
    int N;
    cin >> N;
    vector<int> P(N), inv(N);
    vector<int> C(N);
    for (int i = 0; i < N; ++i)
        cin >> P[i], --P[i];
    for (int i = 0; i < N; ++i)
        inv[P[i]] = i;
    T t(N);
    for (int i = 0; i < N; ++i)
    {
        C[i] = t.sum(0, P[i]);
        t.add(P[i], 1);
    }
    int pre = N; // popped until pre
    int l = 0, r = N - 1;
    vector<pair<int, int>> arr;
    for (int p = N - 1; p >= 0; --p)
    {
        if (C[inv[p]] % 2 == 0)
        {
            if (max(l, inv[p]) > r)
            {
                if (p + 2 == pre)
                {
                    cout << "No" << endl;
                    return 0;
                }
                arr.emplace_back(p + 1, C[inv[p + 1]]);
                for (int x = pre - 1; x > p + 1; --x)
                    arr.emplace_back(x, C[inv[x]] - C[inv[x]] % 2);
                pre = p;
            }
            else
                l = max(l, inv[p]);
        }
        else
        {
            if (l > min(inv[p], r))
            {
                if (p + 2 == pre)
                {
                    cout << "No" << endl;
                    return 0;
                }
                arr.emplace_back(p + 1, C[inv[p + 1]]);
                for (int x = pre - 1; x > p + 1; --x)
                    arr.emplace_back(x, C[inv[x]] - C[inv[x]] % 2);
                pre = p;
            }
            else
                r = min(r, inv[p]);
        }
    }
    reverse(arr.begin(), arr.end());
    cout << "Yes" << endl;
    for (auto [a, b] : arr)
        cout << a + 1 << " " << b + 1 << endl;
    return 0;
}
0