|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
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){ //每次都会将其给覆盖,但是只想将其连成一个链表
- 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();
- }
- }
复制代码
|
|