社区讨论
60求调必关, 前12AC,后面全部TLE
B4324【模板】双向链表参与者 2已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @mlhgc863
- 此快照首次捕获于
- 2026/02/11 11:10 上周
- 此快照最后确认于
- 2026/02/11 12:45 上周
CPP
#include <bits/stdc++.h>
using namespace std;
int n, m;
list<int> l;
vector<bool> List;
void insertx(int a, int x, int y)
{
if(x == y)
{
return;
}
if(List[x])
{
l.remove(x);
List[x] = false;
}
auto itr = find(l.begin(), l.end(), y);
if(itr == l.end())
{
return;
}
if(a == 1)
{
l.insert(itr, x);
}
else
{
++itr;
l.insert(itr, x);
}
List[x] = true;
return;
}
void deletex(int x)
{
if(List[x])
{
l.remove(x);
List[x] = false;
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
List.resize(n + 1, true);
for(int i = 1; i <= n; i++)
{
l.push_back(i);
}
for(int i = 1; i <= m; i++)
{
int a, x, y;
cin >> a;
if(a == 1 || a == 2)
{
cin >> x >> y;
insertx(a, x, y);
}
else
{
cin >> x;
deletex(x);
}
}
if(l.empty())
{
cout << "Empty!";
}
else
{
for(auto itr = l.begin(); itr != l.end(); itr++)
{
cout << *itr << " ";
}
}
return 0;
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...