Submission #51083373


Source Code Expand

#include <iostream>
#include <list>
#include <map>
using namespace std;
using ll = long long;
#define REP_(i, a_, b_, a, b, ...) \
  for (int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(v) v.begin(), v.end()

int main() {
  int N, Q;
  cin >> N;

  list<int> A;
  map<int, list<int>::iterator> posM;

  REP(i, N) {
    int val;
    cin >> val;
    A.push_back(val);
    posM[val] = --A.end();
  }

  cin >> Q;
  REP(i, Q) {
    int type;
    cin >> type;
    if (type == 1) {
      int x, y;
      cin >> x >> y;

      auto it = posM[x];
      ++it;
      posM[y] = A.insert(it, y);
    } else {
      int x;
      cin >> x;
      A.erase(posM[x]);
      posM.erase(x);
    }
  }
  for (int val : A) {
    cout << val << " ";
  }
  cout << endl;
}

Submission Info

Submission Time
Task E - Insert or Erase
User noyan
Language C++ 23 (gcc 12.2)
Score 475
Code Size 827 Byte
Status AC
Exec Time 556 ms
Memory 41228 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 556 ms 39924 KiB
random_02.txt AC 370 ms 26680 KiB
random_03.txt AC 379 ms 32244 KiB
random_04.txt AC 130 ms 13252 KiB
random_05.txt AC 377 ms 22276 KiB
random_06.txt AC 237 ms 11180 KiB
random_07.txt AC 333 ms 22200 KiB
random_08.txt AC 133 ms 11840 KiB
random_09.txt AC 313 ms 22220 KiB
random_10.txt AC 164 ms 11288 KiB
random_11.txt AC 275 ms 22224 KiB
random_12.txt AC 41 ms 4312 KiB
random_13.txt AC 420 ms 39872 KiB
random_14.txt AC 313 ms 22288 KiB
random_15.txt AC 288 ms 22196 KiB
random_16.txt AC 435 ms 39920 KiB
random_17.txt AC 317 ms 22276 KiB
random_18.txt AC 276 ms 22224 KiB
random_19.txt AC 129 ms 12948 KiB
random_20.txt AC 252 ms 41228 KiB
random_21.txt AC 149 ms 22196 KiB
sample_01.txt AC 1 ms 3500 KiB
sample_02.txt AC 1 ms 3472 KiB