結果

問題 No.1558 Derby Live
ユーザー sten_sansten_san
提出日時 2022-04-21 18:35:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 4,805 bytes
コンパイル時間 2,428 ms
コンパイル使用メモリ 205,784 KB
実行使用メモリ 9,208 KB
最終ジャッジ日時 2023-09-05 00:35:31
合計ジャッジ時間 10,958 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
9,004 KB
testcase_01 AC 117 ms
8,964 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 91 ms
4,380 KB
testcase_04 AC 43 ms
6,400 KB
testcase_05 AC 52 ms
6,320 KB
testcase_06 AC 87 ms
6,160 KB
testcase_07 AC 4 ms
5,920 KB
testcase_08 AC 82 ms
8,964 KB
testcase_09 AC 87 ms
9,208 KB
testcase_10 AC 88 ms
8,960 KB
testcase_11 AC 91 ms
9,112 KB
testcase_12 AC 90 ms
9,008 KB
testcase_13 AC 93 ms
8,908 KB
testcase_14 AC 97 ms
8,964 KB
testcase_15 AC 102 ms
8,900 KB
testcase_16 AC 104 ms
9,080 KB
testcase_17 AC 107 ms
8,980 KB
testcase_18 AC 107 ms
8,988 KB
testcase_19 AC 108 ms
9,012 KB
testcase_20 AC 113 ms
8,956 KB
testcase_21 AC 108 ms
8,892 KB
testcase_22 AC 111 ms
8,960 KB
testcase_23 AC 115 ms
8,904 KB
testcase_24 AC 108 ms
8,940 KB
testcase_25 AC 113 ms
9,080 KB
testcase_26 AC 114 ms
8,952 KB
testcase_27 AC 111 ms
9,108 KB
testcase_28 AC 112 ms
8,916 KB
testcase_29 AC 114 ms
8,904 KB
testcase_30 AC 108 ms
9,004 KB
testcase_31 AC 111 ms
9,044 KB
testcase_32 AC 113 ms
8,944 KB
testcase_33 AC 1 ms
4,384 KB
testcase_34 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct iofast_t {
    iofast_t() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} iofast;

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return vector(arg, init);
    else return vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

template <typename Container>
auto distance(const Container &c, decltype(begin(c)) iter) {
    return distance(begin(c), iter);
}

template <typename RIter, typename Compare = less<typename iterator_traits<RIter>::value_type>>
auto isort(RIter first, RIter last, Compare comp = Compare()) {
    vector<int> i(distance(first, last));
    iota(begin(i), end(i), 0);
    sort(begin(i), end(i), [&](auto x, auto y) {
        return comp(*(first + x), *(first + y));
    });
    return i;
}

template <typename, template <typename> typename, typename = void_t<>>
struct detect : false_type {};
template <typename T, template <typename> typename Check>
struct detect<T, Check, void_t<Check<T>>> : true_type {};
template <typename T, template <typename> typename Check>
constexpr inline bool detect_v = detect<T, Check>::value;

template <typename T>
using has_member_sort = decltype(declval<T>().sort());

template <typename Container, typename Compare = less<typename Container::value_type>>
auto sorted(Container c, Compare comp = Compare()) {
    if constexpr (detect_v<Container, has_member_sort>) {
        c.sort(comp);
        return c;
    }
    else {
        sort(begin(c), end(c), comp);
        return c;
    }
}

template <typename Container, typename Compare = equal_to<typename Container::value_type>>
auto uniqued(Container c, Compare comp = Compare()) {
    c.erase(unique(begin(c), end(c), comp), end(c));
    return c;
}

template <typename T, typename Compare = less<T>>
T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); }
template <typename T, typename Compare = less<T>>
T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); }

template <size_t N>
struct sperm : std::array<int, N> {
    constexpr static size_t size() {
        return N;
    }

    template <typename ...Args>
    constexpr sperm(Args ...args): perm_() {
        static_assert((std::is_convertible_v<Args, size_t> && ...), "Could not convert to size_t");

        for (size_t i = 0; i < N; ++i) {
            perm_[i] = i;
        }

        if constexpr (1 < sizeof...(Args)) {
            bool f = true;

            size_t p = 0, q = 0;
            for (auto i : { static_cast<size_t>(args)... }) {
                if (f) {
                    f = false; p = i; q = i;
                    continue;
                }
                perm_[p] = i; p = i;
            }
            perm_[p] = q;
        }
    }

    constexpr sperm operator *(const sperm &r) const {
        sperm x;
        for (size_t i = 0; i < N; ++i) {
            x[i] = perm_[r[i]];
        }
        return x;
    }

    constexpr auto &operator [](size_t i) {
        return perm_[i];
    }

    constexpr const auto &operator [](size_t i) const {
        return perm_[i];
    }

private:
    std::array<int, N> perm_;
};

template <size_t N>
auto &operator <<(std::ostream &os, const sperm<N> &sp) {
    os << "(";
    if constexpr (0 < std::size(sp)) {
        os << sp[0];
        for (size_t i = 1; i < std::size(sp); ++i) {
            os << ", " << sp[i];
        }
    }
    os << ")";
    return os;
}

#include <atcoder/segtree>

using rep = sperm<18>;

rep op(rep x, rep y) {
    return y * x;
}

rep elem() {
    return {};
}

using segtree = atcoder::segtree<rep, op, elem>;

int main() {
    int n, m, q; cin >> n >> m >> q;

    segtree seg(m);

    while (q--) {
        int t; cin >> t;

        if (t == 1) {
            int d; cin >> d; --d;

            rep p;
            for (int i = 0; i < n; ++i) {
                cin >> p[i]; --p[i];
            }

            seg.set(d, p);
        }

        if (t == 2) {
            int s; cin >> s;

            auto p = seg.prod(0, s);

            rep q;
            for (int i = 0; i < n; ++i) {
                q[p[i]] = i;
            }

            cout << q[0] + 1;
            for (int i = 1; i < n; ++i) {
                cout << " " << q[i] + 1;
            }
            cout << endl;
        }

        if (t == 3) {
            int l, r; cin >> l >> r; --l;

            auto p = seg.prod(l, r);

            int ans = 0;
            for (int i = 0; i < n; ++i) {
                ans += abs(i - p[i]);
            }

            cout << ans << endl;
        }
    }
}

0