|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- const int N = 2e5 + 5;
- int q, x, y, p, mark[N];
- list<int> l;
- list<int>::iterator it[N], tempit;
- void solve()
- {
- cin >> q;
- while (q--)
- {
- cin >> p;
- if (p == 1)
- {
- cin >> x >> y;
- if (y != 0)
- {
- if (l.empty())
- {
- l.push_front(y);
- it[y] = l.begin();
- }
- if (it[y] == l.end())
- {
- l.push_back(x);
- it[x] = --l.end();
- }
- else
- {
- tempit = it[y];
- tempit++;
- it[x] = l.insert(tempit, x);
- }
- }
- else
- {
- l.push_front(x);
- it[x] = l.begin();
- }
- }
- else
- {
- cin >> x;
- if (mark[x] == 1)
- continue;
- mark[x] = 1;
- l.erase(it[x]);
- }
- }
- cout << l.size() << endl;
- for (tempit = l.begin(); tempit != l.end(); tempit++)
- {
- cout << *tempit << " ";
- }
- }
- signed main()
- {
- int t;
- t = 1;
- while (t--)
- {
- solve();
- }
- }
复制代码
题目描述 $x$
小红拿到了一个数组,初始数组为空,她希望你实现以下两种操作:
1. 翰入 $1 x y$ ,将 $x$ 插入在元素 $y$ 的右边。保证此时数组中没有元素等于 $x$ ,且数组中存在一个 $y$ 。特殊的,如果将 $x$ 插入在数组的最左边,则 $y=0$
2. 输入 $2 x$ ,将元素 $x$ 删除。
请你在所有操作后输出整个数组。
https://ac.nowcoder.com/acm/contest/74362/D
程序发生了段错误,应该怎么修改 |
|