結果

問題 No.1888 Odd Insertion
ユーザー 👑 colognecologne
提出日時 2022-03-25 23:17:00
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,272 bytes
コンパイル時間 3,854 ms
コンパイル使用メモリ 283,660 KB
実行使用メモリ 8,716 KB
最終ジャッジ日時 2024-04-22 08:12:45
合計ジャッジ時間 15,294 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 71 ms
6,940 KB
testcase_07 AC 72 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 71 ms
6,944 KB
testcase_19 AC 71 ms
6,940 KB
testcase_20 AC 71 ms
6,944 KB
testcase_21 AC 72 ms
6,940 KB
testcase_22 AC 71 ms
6,944 KB
testcase_23 AC 72 ms
6,940 KB
testcase_24 AC 72 ms
6,944 KB
testcase_25 AC 72 ms
6,940 KB
testcase_26 AC 354 ms
8,588 KB
testcase_27 AC 359 ms
8,584 KB
testcase_28 AC 357 ms
8,588 KB
testcase_29 AC 71 ms
6,940 KB
testcase_30 AC 70 ms
6,944 KB
testcase_31 AC 69 ms
6,940 KB
testcase_32 AC 355 ms
8,716 KB
testcase_33 AC 350 ms
8,588 KB
testcase_34 AC 359 ms
8,588 KB
testcase_35 AC 351 ms
8,588 KB
testcase_36 AC 357 ms
8,592 KB
testcase_37 AC 347 ms
8,584 KB
testcase_38 AC 349 ms
8,456 KB
権限があれば一括ダウンロードができます

ソースコード

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 le = N - 1;
    vector<pair<int, int>> arr;
    for (int p = N - 1; p >= 0; --p)
    {
        if (inv[p] <= le && C[inv[p]] % 2 == 0)
        {
            arr.emplace_back(p, C[inv[p]]);
            for (int x = pre - 1; x > p; --x)
                arr.emplace_back(x, C[inv[x]] - C[inv[x]] % 2);
            pre = p;
            le = N - 1;
        }
        else if (C[inv[p]] % 2 == 0)
        {
            cout << "No" << endl;
            return 0;
        }
        else
            le = min(le, inv[p]);
    }
    if (pre != 0)
    {
        cout << "No" << endl;
        return 0;
    }
    else
    {
        reverse(arr.begin(), arr.end());
        cout << "Yes" << endl;
        for (auto [a, b] : arr)
            cout << a + 1 << " " << b + 1 << endl;
        return 0;
    }
}
0