Submission #51232513
Source Code Expand
#include <bits/stdc++.h> #ifdef LOCAL #include "debug.h" #else #define debug(...) #endif using int64 = long long; using uint = unsigned int; using uint64 = unsigned long long; bool ckmin(auto& a, auto b) { return b < a ? a = b, 1 : 0; } bool ckmax(auto& a, auto b) { return b > a ? a = b, 1 : 0; } using namespace std; struct Node { int val; Node* prev; Node* next; Node(int val) : val(val) {} }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; map<int, Node*> go; auto Insert = [&](int x, int y) { assert(go.contains(x)); Node* xx = go[x]; Node* yy = new Node(y); xx->next->prev = yy; yy->next = xx->next; yy->prev = xx; xx->next = yy; go[y] = yy; }; auto Delete = [&](int x) { assert(go.contains(x)); Node* xx = go[x]; xx->prev->next = xx->next; xx->next->prev = xx->prev; go.erase(x); }; auto head = new Node(-1), tail = new Node(-2); head->next = tail; tail->prev = head; go[-1] = head, go[-2] = tail; for (int i = n - 1; i >= 0; i--) Insert(-1, a[i]); int q; cin >> q; while (q--) { int op, x, y; cin >> op >> x; if (op == 1) { cin >> y; Insert(x, y); } else { Delete(x); } } for (auto x = head->next; x != tail; x = x->next) { cout << x->val << ' '; } cout << '\n'; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Insert or Erase |
User | xindubawukong |
Language | C++ 20 (gcc 12.2) |
Score | 475 |
Code Size | 1508 Byte |
Status | AC |
Exec Time | 403 ms |
Memory | 42080 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 475 / 475 | ||||
Status |
|
|
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 | 3472 KiB |
random_01.txt | AC | 403 ms | 40984 KiB |
random_02.txt | AC | 252 ms | 26892 KiB |
random_03.txt | AC | 263 ms | 33224 KiB |
random_04.txt | AC | 89 ms | 13380 KiB |
random_05.txt | AC | 285 ms | 25796 KiB |
random_06.txt | AC | 170 ms | 14176 KiB |
random_07.txt | AC | 254 ms | 25056 KiB |
random_08.txt | AC | 101 ms | 13056 KiB |
random_09.txt | AC | 249 ms | 22588 KiB |
random_10.txt | AC | 96 ms | 11324 KiB |
random_11.txt | AC | 213 ms | 22520 KiB |
random_12.txt | AC | 17 ms | 4856 KiB |
random_13.txt | AC | 284 ms | 40936 KiB |
random_14.txt | AC | 235 ms | 25712 KiB |
random_15.txt | AC | 201 ms | 22528 KiB |
random_16.txt | AC | 290 ms | 40956 KiB |
random_17.txt | AC | 227 ms | 25624 KiB |
random_18.txt | AC | 214 ms | 22448 KiB |
random_19.txt | AC | 90 ms | 16116 KiB |
random_20.txt | AC | 226 ms | 42080 KiB |
random_21.txt | AC | 120 ms | 22676 KiB |
sample_01.txt | AC | 1 ms | 3444 KiB |
sample_02.txt | AC | 1 ms | 3476 KiB |