Submission #51082044


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/modint>

namespace {
    using ModInt [[maybe_unused]] = atcoder::modint998244353;
    using Num [[maybe_unused]] = long long int;
    using Vec [[maybe_unused]] = std::vector<Num>;
    using Set [[maybe_unused]] = std::set<Num>;
    using Mset [[maybe_unused]] = std::multiset<Num>;
    using Edges [[maybe_unused]] = std::vector<std::vector<Num>>;

    template<typename T>
    using Q [[maybe_unused]] = std::queue<T>;

    template<typename T>
    using PQ [[maybe_unused]] = std::priority_queue<T, std::vector<T>, std::greater<T>>;
}

void solve(std::istream& is, std::ostream& os) {
    Num n {0};
    is >> n;

    Vec ns(n);
    std::list<Num> lst;
    for(Num i{0}; i<n; ++i) {
        Num a;
        is >> a;
        ns.at(i) = a;
        lst.push_back(a);
    }

    auto it = lst.begin();
    std::map<Num, decltype(it)> elements;
    for(Num i{0}; i<n; ++i) {
        elements[ns.at(i)] = it;
        ++it;
    }

    Num q {0};
    is >> q;
    while(q-- > 0) {
        Num cmd;
        is >> cmd;

        if (cmd == 1) {
            Num x, y;
            is >> x >> y;
            auto it = elements[x];
            ++it;
            elements[y] = lst.insert(it, y);
        } else {
            Num x;
            is >> x;
            auto it = elements[x];
            lst.erase(it);
            elements.erase(x);
        }
    }

    it = lst.begin();
    if (it == lst.end()) {
        os << "\n";
        return;
    }

    for(;;) {
        os << *it;
        ++it;
        if (it == lst.end()) {
            os << "\n";
            break;
        }
        os << " ";
    }
}

int main(void) {
    solve(std::cin, std::cout);
    return 0;
}

Submission Info

Submission Time
Task E - Insert or Erase
User zettsut
Language C++ 20 (gcc 12.2)
Score 475
Code Size 1789 Byte
Status AC
Exec Time 496 ms
Memory 42832 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 2
AC × 24
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
min.txt AC 1 ms 3536 KiB
random_01.txt AC 496 ms 41420 KiB
random_02.txt AC 329 ms 26840 KiB
random_03.txt AC 307 ms 33800 KiB
random_04.txt AC 125 ms 13252 KiB
random_05.txt AC 335 ms 23468 KiB
random_06.txt AC 229 ms 11612 KiB
random_07.txt AC 296 ms 23468 KiB
random_08.txt AC 128 ms 12200 KiB
random_09.txt AC 282 ms 23396 KiB
random_10.txt AC 159 ms 11516 KiB
random_11.txt AC 255 ms 23420 KiB
random_12.txt AC 40 ms 4312 KiB
random_13.txt AC 378 ms 41408 KiB
random_14.txt AC 293 ms 23408 KiB
random_15.txt AC 261 ms 23420 KiB
random_16.txt AC 380 ms 41480 KiB
random_17.txt AC 287 ms 23388 KiB
random_18.txt AC 257 ms 23408 KiB
random_19.txt AC 125 ms 13368 KiB
random_20.txt AC 245 ms 42832 KiB
random_21.txt AC 146 ms 23552 KiB
sample_01.txt AC 1 ms 3556 KiB
sample_02.txt AC 1 ms 3492 KiB