竞赛讨论区 > 救救我的DD(
头像
迷雾之主
发布于 02-04 22:08
+ 关注

救救我的DD(

#include <bits/stdc++.h>

usingnamespacestd;

constintN = 2000100;

typedeflonglongll;

// head 表示头结点的下标

// e[i] 表示节点i的值

// ne[i] 表示节点i的next指针是多少

// idx 存储当前已经用到了哪个点

ll head, e[N], ne[N], idx;

// 初始化

voidinit()

{

head = -1;

idx = 0;

}

// 将x插到头结点

voidadd_to_head(ll x)

{

e[idx] = x, ne[idx] = head, head = idx++;

}

// 将x插到下标是k的点后面

voidadd(ll k, ll x)

{

e[idx] = x, ne[idx] = ne[k], ne[k] = idx++;

}

// 将下标是k的点后面的点删掉

voidremove(ll k)

{

ne[k] = ne[ne[k]];

}

intmain()

{

intm;

cin >> m;

ll size = 0;

init();

map<int, int>mp;

while(m--)

{

ll k, x;

ll op;

cin >> op;

if(op == 1)

{

size++;

cin >> x >> k;

if(k==0)

{

mp[x] = idx;

add_to_head(x);               

}

else

{

mp[x] = idx;

add(mp[k], x);

}

}

else

{

size--;

cin>>k;

if(mp[k]==head) head = ne[head];

elseremove(mp[k-1]);

}        

}

cout << size << endl;

for(inti = head; i != -1; i = ne[i]) cout << e[i] << ' ';

cout << endl;

}

全部评论

(0) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐