题目描述
blablabla
样例
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int ne[N], e[N], idx = 1, head = 0;
void addHead(int x)
{
e[idx] = x;
ne[idx] = head;
head = idx++;
}
void insert(int k, int x)
{
e[idx] = x;
ne[idx] = ne[k];
ne[k] = idx++;
}
void delTail(int x)
{
ne[x] = ne[ne[x]];
}
int main()
{
int M;
scanf("%d", &M);
while (M--)
{
char op[2];
scanf("%s", &op);
int m, n;
switch (op[0])
{
case 'H':
scanf("%d", &m);
addHead(m);
break;
case 'I':
scanf("%d%d", &m, &n);
insert(m, n);
break;
case 'D':
scanf("%d", &m);
if (m) delTail(m);
else head = ne[head];
break;
default:
break;
}
}
int cur = head;
while (cur) printf("%d ", e[cur]), cur = ne[cur];
return 0;
}
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla