-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue_With_Stacks.code-snippets
62 lines (62 loc) · 1.27 KB
/
Queue_With_Stacks.code-snippets
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{
"Queue_With_Stacks": {
"prefix": "Queue_With_Stacks",
"body": [
"struct Stack {",
" ",
" vector < ll > s, GCD;",
" ",
" Stack() {",
" GCD = {0}, s = {};",
" }",
"",
" void push(ll x){",
" s.emplace_back(x);",
" GCD.push_back(__gcd(GCD.back(), x));",
" }",
"",
" ll pop(){",
" ll res = s.back();",
" s.pop_back();",
" GCD.pop_back();",
" return res;",
" }",
" ",
" bool empty(){",
" return s.empty();",
" }",
" ",
" ll GCD_val(){",
" return GCD.back();",
" }",
"",
"};",
"",
"struct Queue_with_Stack {",
"",
" Stack s1, s2;",
"",
" Queue_with_Stack () {",
" s1 = Stack(), s2 = Stack();",
" }",
"",
" void push(ll x){",
" s2.push(x);",
" }",
"",
" void pop(){",
" if(s1.empty())",
" while(!s2.empty())",
" s1.push(s2.pop());",
" s1.pop();",
" }",
"",
" bool is_good(){",
" return __gcd(s1.GCD_val(), s2.GCD_val()) == 1;",
" }",
"",
"};"
],
"description": "Queue_With_Stacks"
}
}