-
Notifications
You must be signed in to change notification settings - Fork 0
/
AcWing826.cpp
47 lines (47 loc) · 868 Bytes
/
AcWing826.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
using namespace std;
const int M = 100100;
int e[M], ne[M], head, idx = 1;
int main()
{
int m;
cin >> m;
while (m--)
{
char s;
cin >> s;
if(s == 'H')
{
int x;
cin >> x;
e[idx] = x;
ne[idx] = head;
head = idx ++;
}
else if(s == 'D')
{
int k;
cin >> k;
if (k == 0)
{
head = ne[head];
}
else
{
ne[k] = ne[ne[k]];
}
}
else if(s == 'I')
{
int k, x;
cin >> k >> x;
e[idx] = x;
ne[idx] = ne[k];
ne[k] = idx ++;
}
}
for (int i = head; i != 0; i = ne[i])
{
cout << e[i] << " ";
}
}