提出 #53566773


ソースコード 拡げる

#include <bits/stdc++.h>

#include "atcoder/segtree"

using namespace std;

constexpr int inf = 1 << 30; // inf > 10^9

int op(int a, int b) {
    return max(a, b);
}
int e() {
    return -inf;
}

vector<int> calc_lis(vector<int> x) {
    const int n = (int)x.size();
    // 座標圧縮
    vector<int> ps;
    for (const auto e : x) {
        ps.push_back(e);
    }
    sort(ps.begin(), ps.end());
    ps.erase(unique(ps.begin(), ps.end()), ps.end());
    for (auto &e : x) {
        e = lower_bound(ps.begin(), ps.end(), e) - ps.begin();
    }
    
    // 動的計画法
    vector<int> ret(n);
    atcoder::segtree<int, op, e> dp(n);
    // ret[i]: 最後の要素が x[i] である条件下の LIS の長さ
    for (int i = 0; i < n; ++i) {
        const int mx = max(0, dp.prod(0, x[i]));
        ret[i] = mx + 1;
        dp.set(x[i], mx + 1);
    }
    return ret;
}

void solve() {
    // 入力
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &e : a) {
        cin >> e;
    }

    // l_lis[i]: 最後の要素が a[i] である条件下の LIS の長さ
    // r_lis[i]: 最初の要素が a[i] である条件下の LIS の長さ
    auto l_lis = calc_lis(a);
    reverse(a.begin(), a.end());
    for (auto &e : a) {
        e = inf - e;
    }
    auto r_lis = calc_lis(a);
    reverse(a.begin(), a.end());
    for (auto &e : a) {
        e = inf - e;
    }
    reverse(r_lis.begin(), r_lis.end());

    const int L = *max_element(l_lis.begin(), l_lis.end());
    vector<int> ans;
    for (int i = 0; i < n; ++i) {
        if (l_lis[i] + r_lis[i] - 1 == L) {
            ans.push_back(i);
        }
    }

    // 出力
    const int m = (int)ans.size();
    cout << m << '\n';
    for (int i = 0; i < m; ++i){
        cout << ans[i] + 1 << (i == m - 1 ? '\n' : ' ');
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while (T--) {
        solve();
    }
}

提出情報

提出日時
問題 F - Useless for LIS
ユーザ Cyanmond
言語 C++ 20 (gcc 12.2)
得点 525
コード長 2027 Byte
結果 AC
実行時間 119 ms
メモリ 10312 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 525 / 525
結果
AC × 2
AC × 46
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 02_hand_00.txt, 02_hand_01.txt, 02_hand_02.txt, 02_hand_03.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3424 KiB
00_sample_01.txt AC 1 ms 3584 KiB
01_random_00.txt AC 76 ms 3588 KiB
01_random_01.txt AC 45 ms 3572 KiB
01_random_02.txt AC 43 ms 3500 KiB
01_random_03.txt AC 45 ms 3452 KiB
01_random_04.txt AC 47 ms 3536 KiB
01_random_05.txt AC 119 ms 10140 KiB
01_random_06.txt AC 118 ms 10248 KiB
01_random_07.txt AC 119 ms 10196 KiB
01_random_08.txt AC 118 ms 10128 KiB
01_random_09.txt AC 118 ms 10128 KiB
01_random_10.txt AC 70 ms 3532 KiB
01_random_11.txt AC 38 ms 3436 KiB
01_random_12.txt AC 39 ms 3516 KiB
01_random_13.txt AC 38 ms 3540 KiB
01_random_14.txt AC 43 ms 3540 KiB
01_random_15.txt AC 115 ms 10188 KiB
01_random_16.txt AC 116 ms 10184 KiB
01_random_17.txt AC 115 ms 10224 KiB
01_random_18.txt AC 102 ms 10156 KiB
01_random_19.txt AC 74 ms 10192 KiB
01_random_20.txt AC 69 ms 3656 KiB
01_random_21.txt AC 37 ms 3660 KiB
01_random_22.txt AC 42 ms 3524 KiB
01_random_23.txt AC 38 ms 3528 KiB
01_random_24.txt AC 31 ms 3532 KiB
01_random_25.txt AC 47 ms 10228 KiB
01_random_26.txt AC 47 ms 10232 KiB
01_random_27.txt AC 48 ms 10248 KiB
01_random_28.txt AC 49 ms 10136 KiB
01_random_29.txt AC 41 ms 10088 KiB
01_random_30.txt AC 88 ms 10152 KiB
01_random_31.txt AC 88 ms 10156 KiB
01_random_32.txt AC 87 ms 10104 KiB
01_random_33.txt AC 87 ms 10224 KiB
01_random_34.txt AC 88 ms 10132 KiB
01_random_35.txt AC 87 ms 10312 KiB
01_random_36.txt AC 84 ms 10204 KiB
01_random_37.txt AC 88 ms 10128 KiB
01_random_38.txt AC 89 ms 10256 KiB
01_random_39.txt AC 85 ms 10248 KiB
02_hand_00.txt AC 1 ms 3444 KiB
02_hand_01.txt AC 36 ms 10140 KiB
02_hand_02.txt AC 84 ms 10156 KiB
02_hand_03.txt AC 82 ms 10180 KiB