結果

問題 No.1888 Odd Insertion
ユーザー 👑 colognecologne
提出日時 2022-03-25 23:01:59
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,282 bytes
コンパイル時間 4,298 ms
コンパイル使用メモリ 282,140 KB
実行使用メモリ 8,720 KB
最終ジャッジ日時 2024-04-22 07:53:00
合計ジャッジ時間 14,947 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 73 ms
6,656 KB
testcase_07 AC 73 ms
6,528 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 74 ms
6,656 KB
testcase_17 WA -
testcase_18 AC 73 ms
6,400 KB
testcase_19 AC 79 ms
6,400 KB
testcase_20 AC 74 ms
6,656 KB
testcase_21 AC 72 ms
6,400 KB
testcase_22 AC 73 ms
6,656 KB
testcase_23 AC 73 ms
6,400 KB
testcase_24 AC 72 ms
6,400 KB
testcase_25 AC 73 ms
6,528 KB
testcase_26 AC 356 ms
8,588 KB
testcase_27 AC 354 ms
8,588 KB
testcase_28 AC 351 ms
8,720 KB
testcase_29 AC 70 ms
6,400 KB
testcase_30 AC 70 ms
6,528 KB
testcase_31 AC 71 ms
6,528 KB
testcase_32 AC 351 ms
8,716 KB
testcase_33 AC 353 ms
8,536 KB
testcase_34 AC 354 ms
8,584 KB
testcase_35 AC 354 ms
8,712 KB
testcase_36 AC 362 ms
8,584 KB
testcase_37 AC 355 ms
8,720 KB
testcase_38 AC 356 ms
8,524 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, ge = 0;
    vector<pair<int, int>> arr;
    for (int p = N - 1; p >= 0; --p)
    {
        if (ge <= inv[p] && 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;
            ge = 0;
        }
        else
        {
            if (C[inv[p]] % 2 == 0)
                ge = max(ge, inv[p]);
            else
                le = min(le, inv[p]);
        }
    }
    if (pre != 0)
    {
        cout << "No" << endl;
    }
    else
    {
        reverse(arr.begin(), arr.end());
        cout << "Yes" << endl;
        for (auto [a, b] : arr)
            cout << a + 1 << " " << b + 1 << endl;
    }
}
0