algo — C++23 日本語リファレンス GitHub

test/yosupo/data_structure/persistent_queue.test.cpp

AC · 最終更新 2026-10-23 · GitHub

問題: https://judge.yosupo.jp/problem/persistent_queue

依存するヘッダ(1)
実装
// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/persistent_queue
#include <iostream>
#include <vector>
#include "persistent_ds/persistent_queue.hpp"

int main(void) {
    int q;
    std::cin >> q;
    std::vector<PersistentQueue<int>> qs;
    qs.emplace_back();
    while (q--) {
        int t;
        std::cin >> t;
        if (t == 0) {
            int k, x;
            std::cin >> k >> x;
            qs.emplace_back(qs[k + 1].emplace(x));
        } else {
            int k;
            std::cin >> k;
            std::cout << qs[k + 1].top() << '\n';
            qs.emplace_back(qs[k + 1].pop());
        }
    }

    return 0;
}