buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
#include <iostream> #define MAX 100000 int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return i * 2 + 1; } int main() { int i, H, A[MAX + 1]; std::cin >> H; for (i = 1; i <= H; ++i) std::cin >> A[i]; for (i = 1; i <= H; ++i) { std::cout << "node " << i << ": ke...
#include <iostream> #define MAX 100000 int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return i * 2 + 1; } int main() { int i, H, A[MAX + 1]; std::cin >> H; for (i = 1; i <= H; ++i) std::cin >> A[i]; for (i = 1; i <= H; ++i) { std::cout << "node " << i << ": ke...
[["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6]]
1
228
2
#include <iostream> using namespace std; int main() { int n; int H[251]; cin >> n; for (int i = 1; i < n + 1; ++i) { cin >> H[i]; } for (int i = 1; i < n + 1; ++i) { if (i == 1) { cout << "node " << i << ": key = " << H[i] << ", left key = " << H[i * 2] << ", right key = " << H[i *...
#include <iostream> using namespace std; int main() { int n; int H[251]; cin >> n; for (int i = 1; i < n + 1; ++i) { cin >> H[i]; } for (int i = 1; i < n + 1; ++i) { if (i == 1) { cout << "node " << i << ": key = " << H[i] << ", left key = " << H[i * 2] << ", right key = " << H[i *...
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 16, 31, 16, 31, 16, 31, 16, 17, 151]]
1
376
4
#include <bits/stdc++.h> #define rep(i, a) for (i = 0; i < a; i++) using namespace std; int main(void) { int i, H, buf; vector<int> A; cin >> H; rep(i, H) { cin >> buf; A.push_back(buf); } rep(i, H) { cout << "node" << i + 1 << ": key = " << A[i] << ", "; if (i > 0) cout << "parent k...
#include <bits/stdc++.h> #define rep(i, a) for (i = 0; i < a; i++) using namespace std; int main(void) { int i, H, buf; vector<int> A; cin >> H; rep(i, H) { cin >> buf; A.push_back(buf); } rep(i, H) { cout << "node " << i + 1 << ": key = " << A[i] << ", "; if (i > 0) cout << "parent ...
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
194
2
/* ALDS1_9_A: Complete Binary Tree */ #include <cstdio> #include <iostream> inline bool between(int value, int begin, int end) { return begin <= value && value <= end; } int main() { int n_nodes; scanf("%d\n", &n_nodes); int tree[n_nodes + 1]; for (int i = 1; i <= n_nodes; i++) scanf("%d", &tree[i]); ...
/* ALDS1_9_A: Complete Binary Tree */ #include <cstdio> #include <iostream> inline bool between(int value, int begin, int end) { return begin <= value && value <= end; } int main() { int n_nodes; scanf("%d\n", &n_nodes); int tree[n_nodes + 1]; for (int i = 1; i <= n_nodes; i++) scanf("%d", &tree[i]); ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
220
2
#include <cstdio> using namespace std; int parent(int x) { return x / 2; } int left(int x) { return x * 2; } int right(int x) { return (x * 2) + 1; } int A[600]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &A[i]); for (int i = 1; i <= n; i++) { printf("node %d: ", ...
#include <cstdio> using namespace std; int parent(int x) { return x / 2; } int left(int x) { return x * 2; } int right(int x) { return (x * 2) + 1; } int A[600]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &A[i]); for (int i = 1; i <= n; i++) { printf("node %d: ", ...
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
220
2
#include <iostream> using namespace std; const int MAX = 1000000; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } int main() { int H, i, A[MAX + 1]; cin >> H; for (int i = 1; i <= H; ++i) { cin >> A[i]; } for (int i = 1; i <= H; ++i) { cou...
#include <iostream> using namespace std; const int MAX = 1000000; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } int main() { int H, i, A[MAX + 1]; cin >> H; for (int i = 1; i <= H; ++i) { cin >> A[i]; } for (int i = 1; i <= H; ++i) { cou...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
223
6
#include <algorithm> #include <cstdio> #include <vector> using namespace std; int main() { int n; scanf("%d", &n); auto H = vector<int>(n); for (auto it = H.begin(); it != H.end(); it++) { scanf("%d", &(*it)); } for (auto it = H.begin(); it != H.end(); it++) { int idx = distance(H.begin(), it); ...
#include <algorithm> #include <cstdio> #include <vector> using namespace std; int main() { int n; scanf("%d", &n); auto H = vector<int>(n); for (auto it = H.begin(); it != H.end(); it++) { scanf("%d", &(*it)); } for (auto it = H.begin(); it != H.end(); it++) { int idx = distance(H.begin(), it); ...
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
1
234
2
#include <iostream> #include <vector> using namespace std; int main() { int n, i; cin >> n; vector<int> h(n); for (i = 0; i < n; i++) { cin >> h[i]; } for (i = 0; i < n; i++) { cout << "node " << i + 1 << ": key=" << h[i] << ", "; if (i != 0) { cout << "parent key = " << h[((i + 1) / 2)...
#include <iostream> #include <vector> using namespace std; int main() { int n, i; cin >> n; vector<int> h(n); for (i = 0; i < n; i++) { cin >> h[i]; } for (i = 0; i < n; i++) { cout << "node " << i + 1 << ": key = " << h[i] << ", "; if (i != 0) { cout << "parent key = " << h[((i + 1) / ...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
207
2
#include <iostream> using namespace std; #define MAX 250 int parent(int key) { return key / 2; } int right(int key) { return (key * 2) + 1; } int left(int key) { return key * 2; } int main() { int s, T[MAX]; cin >> s; for (int i = 1; i <= s; i++) { cin >> T[i]; } for (int i = 1; i <= s; i++) { cou...
#include <iostream> using namespace std; #define MAX 250 int parent(int key) { return key / 2; } int right(int key) { return (key * 2) + 1; } int left(int key) { return key * 2; } int main() { int s, T[MAX]; cin >> s; for (int i = 1; i <= s; i++) { cin >> T[i]; } for (int i = 1; i <= s; i++) { cou...
[["-", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6], ["+", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6]]
1
215
6
#include <iostream> #define ll long long using namespace std; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } int main() { int H; ll A[251]; cin >> H; for (int i = 1; i <= H; i++) cin >> A[i]; for (int i = 1; i <= H; i++) { cout << "node...
#include <iostream> #define ll long long using namespace std; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } int main() { int H; ll A[251]; cin >> H; for (int i = 1; i <= H; i++) cin >> A[i]; for (int i = 1; i <= H; i++) { cout << "node...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
228
2
#include <iostream> using namespace std; int main() { int A[251], n; cin >> n; for (int i = 1; i <= n; i++) cin >> A[i]; for (int i = 1; i <= n; i++) { cout << "node " << i << ": key = " << A[i] << ", "; if (i / 2 > 0 && i / 2 <= n) cout << "parent key = " << A[i / 2] << ", "; if (2 * i <...
#include <iostream> using namespace std; int main() { int A[251], n; cin >> n; for (int i = 1; i <= n; i++) cin >> A[i]; for (int i = 1; i <= n; i++) { cout << "node " << i << ": key = " << A[i] << ", "; if (i / 2 > 0 && i / 2 <= n) cout << "parent key = " << A[i / 2] << ", "; if (2 * i <...
[["-", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6], ["+", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6]]
1
174
2
#include <bits/stdc++.h> #define H 255 using namespace std; int main() { int h, A[H]; cin >> h; for (int i = 1; i <= h; i++) cin >> A[i]; for (int i = 1; i <= h; i++) { cout << "node " << i << ": key = "; cout << A[i] << ","; if (i != 1) cout << "parent key = " << A[i / 2] << ", "; if...
#include <bits/stdc++.h> #define H 255 using namespace std; int main() { int h, A[H]; cin >> h; for (int i = 1; i <= h; i++) cin >> A[i]; for (int i = 1; i <= h; i++) { cout << "node " << i << ": key = "; cout << A[i] << ", "; if (i != 1) cout << "parent key = " << A[i / 2] << ", "; i...
[["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6]]
1
171
2
#include <bits/stdc++.h> using namespace std; #define N 100000 int main() { int H, Heap[N + 1]; cin >> H; for (int i = 1; i <= H; i++) { cin >> Heap[i]; } for (int i = 1; i <= H; i++) { cout << "node" << i << ": key = " << Heap[i] << ", "; if (i / 2 >= 1) { cout << "parent key = " << ...
#include <bits/stdc++.h> using namespace std; #define N 100000 int main() { int H, Heap[N + 1]; cin >> H; for (int i = 1; i <= H; i++) { cin >> Heap[i]; } for (int i = 1; i <= H; i++) { cout << "node " << i << ": key = " << Heap[i] << ", "; if (i / 2 >= 1) { cout << "parent key = " <<...
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
181
2
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_9_A //????§£????????? #include <iostream> using namespace std; int main() { int N, H[250]; cin >> N; for (int i = 0; i < N; i++) cin >> H[i]; int k = 0; while (k < N) { cout << "node " << k + 1 << ": key = " << H[k] << ", "; int ...
#include <iostream> using namespace std; int main() { int N, H[250]; cin >> N; for (int i = 0; i < N; i++) cin >> H[i]; int k = 0; while (k < N) { cout << "node " << k + 1 << ": key = " << H[k] << ", "; int l = (k + 1) / 2 - 1; if (k != 0) cout << "parent key = " << H[l] << ", "; ...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
191
6
#include "bits/stdc++.h" #include <unordered_set> #define REP(i, n) for (decltype(n) i = 0; i < (n); i++) #define REP2(i, x, n) for (decltype(x) i = (x); i < (n); i++) #define REP3(i, x, n) for (decltype(x) i = (x); i <= (n); i++) #define RREP(i, n) for (decltype(n) i = (n)-1; i >= 0; i--) #define ALL(a) (a).begin(),...
#include "bits/stdc++.h" #include <unordered_set> #define REP(i, n) for (decltype(n) i = 0; i < (n); i++) #define REP2(i, x, n) for (decltype(x) i = (x); i < (n); i++) #define REP3(i, x, n) for (decltype(x) i = (x); i <= (n); i++) #define RREP(i, n) for (decltype(n) i = (n)-1; i >= 0; i--) #define ALL(a) (a).begin(),...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
338
2
#include <iostream> using namespace std; #define MAX 100000 int parent(int i) { return i / 2; } int left(int i) { return i * 2; } int right(int i) { return i * 2 + 1; } int main(void) { int H, i, A[MAX + 1]; cin >> H; for (i = 1; i <= H; i++) { cin >> A[i]; } for (i = 1; i <= H; i++) { cout << ...
#include <iostream> using namespace std; #define MAX 100000 int parent(int i) { return i / 2; } int left(int i) { return i * 2; } int right(int i) { return i * 2 + 1; } int main(void) { int H, i, A[MAX + 1]; cin >> H; for (i = 1; i <= H; i++) { cin >> A[i]; } for (i = 1; i <= H; i++) { cout << ...
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
225
2
#include <iostream> #include <vector> #define DUMMYKEY 0 using namespace std; void Output(const vector<int> &Heap) { for (int i = 1; i <= Heap.size(); i++) { cout << "node " << i << ": "; cout << "key = " << Heap[i] << ", "; if (i / 2 >= 1) { cout << "parent key = " << Heap[i / 2] << ", "; } ...
#include <iostream> #include <vector> #define DUMMYKEY 0 using namespace std; void Output(const vector<int> &Heap) { for (int i = 1; i < Heap.size(); i++) { cout << "node " << i << ": "; cout << "key = " << Heap[i] << ", "; if (i / 2 >= 1) { cout << "parent key = " << Heap[i / 2] << ", "; } ...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18]]
1
234
2
#include <iostream> #include <math.h> using namespace std; int main() { int n; cin >> n; int *pt; pt = new int[n]; for (int i = 1; i <= n; i++) cin >> pt[i]; for (int i = 1; i <= n; i++) { cout << "node " << i << ": key = " << pt[i] << ", "; if (i != 1) cout << "parent key = " << pt[int(fl...
#include <iostream> #include <math.h> using namespace std; int main() { int n; cin >> n; int *pt; pt = new int[n]; for (int i = 1; i <= n; i++) cin >> pt[i]; for (int i = 1; i <= n; i++) { cout << "node " << i << ": key = " << pt[i] << ", "; if (i != 1) cout << "parent key = " << pt[int(fl...
[["-", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6], ["+", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6]]
1
178
2
#include <algorithm> #include <iostream> #include <map> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define NIL -1 #define N 500001 int A[N], n; int par(int i) { return i / 2; } int lef(int i) { return i * 2; } int rig(int i) { return i *...
#include <algorithm> #include <iostream> #include <map> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define NIL -1 #define N 500001 int A[N], n; int par(int i) { return i / 2; } int lef(int i) { return i * 2; } int rig(int i) { return i *...
[["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
246
6
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define irep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++) using namespace std; // namespace utils namespace utils { template <typename T> void print(vector<vector<T>> mat) { rep...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define irep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++) using namespace std; // namespace utils namespace utils { template <typename T> void print(vector<vector<T>> mat) { rep...
[["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6]]
1
401
2
#include <stdio.h> #define N 100000 int parent_key(int); int left_key(int); int right_key(int); int main() { int i, n, A[N + 1]; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &A[i]); } for (i = 1; i <= n; i++) { printf("node %d: key = %d, ", i, A[i]); if (parent_key(i) >= 1) print...
#include <stdio.h> #define N 100000 int parent_key(int); int left_key(int); int right_key(int); int main() { int i, n, A[N + 1]; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &A[i]); } for (i = 1; i <= n; i++) { printf("node %d: key = %d, ", i, A[i]); if (parent_key(i) >= 1) print...
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
231
6
#include <bits/stdc++.h> using namespace std; int p(int i) { return i / 2; } int l(int i) { return i * 2; } int r(int i) { return i * 2 + 1; } int main() { int h, a[300]; cin >> h; for (int i = 1; i <= h; i++) cin >> a[i]; for (int i = 1; i <= h; i++) { cout << "node" << i << ": key = " << a[i] << ", ";...
#include <bits/stdc++.h> using namespace std; int p(int i) { return i / 2; } int l(int i) { return i * 2; } int r(int i) { return i * 2 + 1; } int main() { int h, a[300]; cin >> h; for (int i = 1; i <= h; i++) cin >> a[i]; for (int i = 1; i <= h; i++) { cout << "node " << i << ": key = " << a[i] << ", "...
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
208
2
#include <stdio.h> #define H 250 int main() { int i, size, a[H]; scanf("%d", &size); for (i = 1; i <= size; i++) scanf("%d", &a[i]); for (i = 1; i <= size; i++) { printf("node %d: key = %d, ", i, a[i]); if (i / 2 >= 1) printf("parent key = %d,", a[i / 2]); if (i * 2 <= size) pri...
#include <stdio.h> #define H 250 int main() { int i, size, a[H]; scanf("%d", &size); for (i = 1; i <= size; i++) scanf("%d", &a[i]); for (i = 1; i <= size; i++) { printf("node %d: key = %d, ", i, a[i]); if (i / 2 >= 1) printf("parent key = %d, ", a[i / 2]); if (i * 2 <= size) p...
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
165
6
#include <iostream> #include <vector> using namespace std; struct Node { int key, pk, lk, rk; }; int main() { int n, x; Node temp; vector<int> data; vector<Node> tree; cin >> n; for (int i = 0; i < n; i++) { cin >> x; data.push_back(x); } for (int i = 0; i < n; i++) { temp.key = data[...
#include <iostream> #include <vector> using namespace std; struct Node { int key, pk, lk, rk; }; int main() { int n, x; Node temp; vector<int> data; vector<Node> tree; cin >> n; for (int i = 0; i < n; i++) { cin >> x; data.push_back(x); } for (int i = 0; i < n; i++) { temp.key = data[...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
309
2
#include <iostream> using namespace std; #define MAX 100000 int Parent(int i) { return i / 2; } int Left(int i) { return 2 * i; } int Right(int i) { return 2 * i + 1; } int main() { int h, A[MAX + 1]; cin >> h; for (int i = 1; i <= h; i++) cin >> A[i]; for (int i = 1; i <= h; i++) { cout << "node " ...
#include <iostream> using namespace std; #define MAX 100000 int Parent(int i) { return i / 2; } int Left(int i) { return 2 * i; } int Right(int i) { return 2 * i + 1; } int main() { int h, A[MAX + 1]; cin >> h; for (int i = 1; i <= h; i++) cin >> A[i]; for (int i = 1; i <= h; i++) { cout << "node " ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
222
2
#include <cmath> #include <iostream> #include <vector> using namespace std; int main() { int32_t H; cin >> H; vector<int32_t> heap(H); for (int32_t i = 0; i < H; i++) { cin >> heap[i]; } for (int32_t i = 0; i < H; i++) { cout << "node " << (i + 1) << ": "; cout << "key = " << heap[i] << ", "...
#include <cmath> #include <iostream> #include <vector> using namespace std; int main() { int32_t H; cin >> H; vector<int32_t> heap(H); for (int32_t i = 0; i < H; i++) { cin >> heap[i]; } for (int32_t i = 0; i < H; i++) { cout << "node " << (i + 1) << ": "; cout << "key = " << heap[i] << ", "...
[["-", 31, 16, 31, 2, 3, 4, 0, 16, 12, 13], ["+", 31, 16, 31, 2, 3, 4, 0, 16, 12, 13], ["-", 0, 16, 31, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 16, 31, 2, 3, 4, 0, 16, 12, 13]]
1
202
4
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <stdio.h> #include <string> #include <vector> #define MAX 1000000000000000000LL long long inf = 1000000007; using namespace std; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i - ...
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <stdio.h> #include <string> #include <vector> #define MAX 1000000000000000000LL long long inf = 1000000007; using namespace std; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + ...
[["-", 0, 14, 8, 9, 0, 37, 0, 16, 17, 33], ["+", 0, 14, 8, 9, 0, 37, 0, 16, 17, 72]]
1
234
2
#include <stdio.h> #define N 2000000 int main() { int n; scanf("%d", &n); int i; int A[N]; for (i = 1; i <= n; i++) { scanf("%d", &A[i]); } for (i = 1; i <= n; i++) { printf("node %d: key = %d, ", i, A[i]); if (i / 2 > 0) printf("parent key = %d, ", A[i / 2]); if (i * 2 < n) ...
#include <stdio.h> #define N 2000000 int main() { int n; scanf("%d", &n); int i; int A[N]; for (i = 1; i <= n; i++) { scanf("%d", &A[i]); } for (i = 1; i <= n; i++) { printf("node %d: key = %d, ", i, A[i]); if (i / 2 > 0) printf("parent key = %d, ", A[i / 2]); if (i * 2 <= n) ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
1
170
4
#include <cstdio> #include <iostream> #include <string> using namespace std; #define MAX_H 251 int main() { int h = 0; scanf("%d", &h); int heap[MAX_H] = {0}; for (int i = 1; i <= h; i++) { scanf("%d", &heap[i]); } for (int i = 1; i <= h; i++) { int parent = heap[i / 2]; int left = heap[i * 2]...
#include <cstdio> #include <iostream> #include <string> using namespace std; #define MAX_H 251 int main() { int h = 0; scanf("%d", &h); int heap[MAX_H] = {0}; for (int i = 1; i <= h; i++) { scanf("%d", &heap[i]); } for (int i = 1; i <= h; i++) { int parent = heap[i / 2]; int left = heap[i * 2]...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 0, 57, 15, 339, 51, 16, 31, 23, 0, 24], ["+", 15, 339, 51, 16, 31, 23, 0, 16, 31, 22], ["+", 15, 339, 51, 16, 31, 23, 0, 16, 17, 85], ["+", 15, 339, 51, 16, 31, 23, 0, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 31, 23, 0, 2...
1
207
8
/* * Problem Description: Heaps - Complete Binary Tree * Category: * Author: Khan * Date: 17th October, 2017 */ #include <iostream> #define MAXN 100000 using namespace std; int parent(int i) { return i / 2; } int leftChild(int i) { return i * 2; } int rightChild(int i) { return i * 2 + 1; } int main(int argc, ...
/* * Problem Description: Heaps - Complete Binary Tree * Category: * Author: Khan * Date: 17th October, 2017 */ #include <iostream> #define MAXN 100000 using namespace std; int parent(int i) { return i / 2; } int leftChild(int i) { return i * 2; } int rightChild(int i) { return i * 2 + 1; } int main(int argc, ...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
226
6
#include <iostream> using namespace std; const int kMaxN = 100000; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } int main() { int n; int A[kMaxN]; cin >> n; for (int i = 1; i <= n; i++) { cin >> A[i]; } for (int i = 1; i <= n; i++) {...
#include <iostream> using namespace std; const int kMaxN = 100000; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } int main() { int n; int A[kMaxN]; cin >> n; for (int i = 1; i <= n; i++) { cin >> A[i]; } for (int i = 1; i <= n; i++) {...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
223
2
#include <bits/stdc++.h> using namespace std; int parent(int i) { return i / 2; } int left(int i) { return i * 2; } int right(int i) { return i * 2 + 1; } int main() { int H, tree[100001]; scanf("%d", &H); for (int i = 1; i <= H; ++i) { scanf("%d", &tree[i]); } for (int i = 1; i <= H; ++i) { printf(...
#include <bits/stdc++.h> using namespace std; int parent(int i) { return i / 2; } int left(int i) { return i * 2; } int right(int i) { return i * 2 + 1; } int main() { int H, tree[100001]; scanf("%d", &H); for (int i = 1; i <= H; ++i) { scanf("%d", &tree[i]); } for (int i = 1; i <= H; ++i) { printf(...
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
212
2
#include <bits/stdc++.h> using namespace std; int parent(int i) { return i / 2; } int left(int i) { return i * 2; } int right(int i) { return i * 2 + 1; } int main() { int h, tree[100001]; scanf("%d", &h); for (int i = 1; i <= h; i++) scanf("%d", &tree[i]); for (int i = 1; i <= h; i++) { printf("node %d...
#include <bits/stdc++.h> using namespace std; int parent(int i) { return i / 2; } int left(int i) { return i * 2; } int right(int i) { return i * 2 + 1; } int main() { int h, tree[100001]; scanf("%d", &h); for (int i = 1; i <= h; i++) scanf("%d", &tree[i]); for (int i = 1; i <= h; i++) { printf("node %d...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
210
2
#include <bits/stdc++.h> using namespace std; int parent(int i) { return i / 2; } int left(int i) { return i * 2; } int right(int i) { return i * 2 + 1; } int main() { int H, tree[100001]; scanf("%d", &H); for (int i = 1; i <= H; i++) scanf("%d", &tree[i]); for (int i = 1; i <= H; i++) { cout << "node "...
#include <bits/stdc++.h> using namespace std; int parent(int i) { return i / 2; } int left(int i) { return i * 2; } int right(int i) { return i * 2 + 1; } int main() { int H, tree[100001]; scanf("%d", &H); for (int i = 1; i <= H; i++) scanf("%d", &tree[i]); for (int i = 1; i <= H; i++) { cout << "node "...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
225
2
#include <stdio.h> void check_parent(int i, int a[], int n) { if (i - 1 < 0) return; printf("parent key = %d,", a[(i - 1) / 2]); printf(" "); } void left_key(int i, int a[], int n) { if (i * 2 + 1 >= n) return; printf("left key = %d,", a[i * 2 + 1]); printf(" "); } void right_key(int i, int a[], ...
#include <stdio.h> void check_parent(int i, int a[], int n) { if (i - 1 < 0) return; printf("parent key = %d,", a[(i - 1) / 2]); printf(" "); } void left_key(int i, int a[], int n) { if (i * 2 + 1 >= n) return; printf("left key = %d,", a[i * 2 + 1]); printf(" "); } void right_key(int i, int a[], ...
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
1
283
2
#include <iostream> using namespace std; struct Node { int key; int parent; int left; int right; }; int h; void print(Node t[]) { for (int i = 1; i < h + 1; i++) { cout << "node" << i << ": "; cout << "key = " << t[i].key << ", "; if (t[i].parent != 0) cout << "parent key = " << t[t[i].pa...
#include <iostream> using namespace std; struct Node { int key; int parent; int left; int right; }; int h; void print(Node t[]) { for (int i = 1; i < h + 1; i++) { cout << "node " << i << ": "; cout << "key = " << t[i].key << ", "; if (t[i].parent != 0) cout << "parent key = " << t[t[i].p...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
274
2
#include <cstdio> #include <iostream> using namespace std; int N; int A[300]; int parent(int i) { return i / 2; } int leftchild(int i) { return 2 * i; } int rightchild(int i) { return 2 * i + 1; } int main() { cin >> N; for (int i = 1; i <= N; i++) { cin >> A[i]; } for (int i = 1; i <= N; i++) { int p...
#include <cstdio> #include <iostream> using namespace std; int N; int A[300]; int parent(int i) { return i / 2; } int leftchild(int i) { return 2 * i; } int rightchild(int i) { return 2 * i + 1; } int main() { cin >> N; for (int i = 1; i <= N; i++) { cin >> A[i]; } for (int i = 1; i <= N; i++) { int p...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
228
6
#include <algorithm> #include <stdio.h> using namespace std; #define NIL -1 #define MAX 250 int A[MAX]; void printHeap(int n) { for (int i = 0; i < n; i++) { printf("node %d: key = %d, ", i + 1, A[i]); if (i + 1 != 1) { printf("parent key = %d, ", A[(i + 1) / 2 - 1]); } if (A[2 * (i + 1) - 1] ...
#include <algorithm> #include <stdio.h> using namespace std; #define NIL -2000000001 #define MAX 250 int A[MAX]; void printHeap(int n) { for (int i = 0; i < n; i++) { printf("node %d: key = %d, ", i + 1, A[i]); if (i + 1 != 1) { printf("parent key = %d, ", A[(i + 1) / 2 - 1]); } if (A[2 * (i +...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18]]
1
284
6
// 2分ヒープ #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <stack> #include <vector> using namespace std; #define MAX_H 250 const int INV = -2147483645; int main(void) { int H, node, parent, left, right; int ary_BinaryHeap[MAX_H + 1]; fo...
// 2分ヒープ #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <stack> #include <vector> using namespace std; #define MAX_H 250 const int INV = -2147483645; int main(void) { int H, node, parent, left, right; int ary_BinaryHeap[MAX_H + 1]; fo...
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22]]
1
268
10
#include <cstdio> int main() { int n; scanf("%d", &n); int heap[n + 1]; for (int i = 1; i <= n; ++i) scanf("%d", &heap[i]); for (int i = 1; i <= n; ++i) { printf("node %d: ", i); printf("key = %d, ", heap[i]); if (i > 1) printf("parent key = %d: ", heap[i / 2]); if (2 * i <= n) ...
#include <cstdio> int main() { int n; scanf("%d", &n); int heap[n + 1]; for (int i = 1; i <= n; ++i) scanf("%d", &heap[i]); for (int i = 1; i <= n; ++i) { printf("node %d: ", i); printf("key = %d, ", heap[i]); if (i > 1) printf("parent key = %d, ", heap[i / 2]); if (2 * i <= n) ...
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
171
2
#include <iostream> using namespace std; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } int main() { int H; cin >> H; int A[H + 1]; for (int i = 1; i <= H; i++) cin >> A[H]; for (int i = 1; i <= H; i++) { cout << "node " << i << ": key...
#include <iostream> using namespace std; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } int main() { int H; cin >> H; int A[H + 1]; for (int i = 1; i <= H; i++) cin >> A[i]; for (int i = 1; i <= H; i++) { cout << "node " << i << ": key...
[["-", 8, 1, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 8, 1, 0, 16, 12, 69, 341, 342, 0, 22]]
1
214
2
/* * ALDS1_9_A.cpp * * Created on: May 5, 2018 * Author: 13743 */ #include <iostream> using namespace std; int main() { int n; int T[251]; cin >> n; for (int i = 0; i < n; i++) { cin >> T[i + 1]; } for (int i = 1; i <= n; i++) { cout << "node " << i << " key = " << T[i] << ", "; ...
/* * ALDS1_9_A.cpp * * Created on: May 5, 2018 * Author: 13743 */ #include <iostream> using namespace std; int main() { int n; int T[251]; cin >> n; for (int i = 0; i < n; i++) { cin >> T[i + 1]; } for (int i = 1; i <= n; i++) { cout << "node " << i << ": key = " << T[i] << ", "; ...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
177
2
#include <iostream> using namespace std; #define MAX 100000 int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } int main() { int H; int A[MAX + 1]; cin >> H; for (int i = 1; i <= H; i++) { cin >> A[i]; } for (int i = 1; i <= H; i++) { co...
#include <iostream> using namespace std; #define MAX 100000 int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } int main() { int H; int A[MAX + 1]; cin >> H; for (int i = 1; i <= H; i++) { cin >> A[i]; } for (int i = 1; i <= H; i++) { co...
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
225
2
#include <iostream> #include <map> #include <set> #include <string> using namespace std; #define MAX 100000 int parent(int i) { return i / 2; } int left(int i) { return i * 2; } int right(int i) { return i * 2 + 1; } int main() { int H, i, A[MAX + 1]; cin >> H; for (int i = 1; i <= H; i++) { cin >> A[i]; ...
#include <iostream> #include <map> #include <set> #include <string> using namespace std; #define MAX 100000 int parent(int i) { return i / 2; } int left(int i) { return i * 2; } int right(int i) { return i * 2 + 1; } int main() { int H, i, A[MAX + 1]; cin >> H; for (int i = 1; i <= H; i++) { cin >> A[i]; ...
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
226
4
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; #define N 400 #define NIL -2100000000 int key[N]; int parent(int i) { return i / 2; } int leftc(int i) { return 2 * i; } int rightc(int i) { return 2 * i + 1; } int main() { int n, data; scanf("%d", &n); for (int i = 0; i < N; i++...
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; #define N 600 #define NIL -2100000000 int key[N]; int parent(int i) { return i / 2; } int leftc(int i) { return 2 * i; } int rightc(int i) { return 2 * i + 1; } int main() { int n, data; scanf("%d", &n); for (int i = 0; i < N; i++...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
259
4
#include <algorithm> // require sort next_permutation count __gcd reverse etc. #include <cctype> // require tolower, toupper #include <cfloat> #include <climits> #include <cmath> // require fabs #include <cstdio> // require scanf printf #include <cstdlib> // require abs exit atof atoi #include <cstring> // requir...
#include <algorithm> // require sort next_permutation count __gcd reverse etc. #include <cctype> // require tolower, toupper #include <cfloat> #include <climits> #include <cmath> // require fabs #include <cstdio> // require scanf printf #include <cstdlib> // require abs exit atof atoi #include <cstring> // requir...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
282
4
class Node def initialize(i, key) @index = i @key = key @parent_key = nil @left_key = nil @right_key = nil end def to_s str = "node #{index}: key = #{key}, " str += "parent_key = #{@parent_key.key}, " unless @parent_key.nil? str += "left_key = #{@left_key.key}, " unless @left_key....
class Node def initialize(i, key) @index = i @key = key @parent_key = nil @left_key = nil @right_key = nil end def to_s str = "node #{index}: key = #{key}, " str += "parent key = #{@parent_key.key}, " unless @parent_key.nil? str += "left key = #{@left_key.key}, " unless @left_key....
[["-", 8, 736, 0, 745, 8, 755, 12, 557, 0, 6], ["+", 8, 736, 0, 745, 8, 755, 12, 557, 0, 6]]
4
244
6
class Node attr_accessor :id, :key, :parent, :left, :right def initialize(id, key) @id = id @key = key @parent = nil @left = nil @right = nil end def to_s parent_s = if @parent != nil "parent key = #{@parent.key}, " else "" end left_s = if @...
class Node attr_accessor :id, :key, :parent, :left, :right def initialize(id, key) @id = id @key = key @parent = nil @left = nil @right = nil end def to_s parent_s = if @parent != nil "parent key = #{@parent.key}, " else "" end left_s = if @...
[["-", 196, 196, 8, 734, 0, 121, 15, 738, 17, 47], ["+", 196, 196, 8, 734, 0, 121, 15, 738, 17, 20]]
4
300
4
class Node attr_accessor :key, :parent, :left, :right def initialize(key) @key = key end end n = gets.to_i heap = [] gets.split.map(&:to_i).each{ |i| heap << Node.new(i) } heap.unshift nil (1..n).each do |i| heap[i].parent = heap[i/2] if i > 0 heap[i].left = heap[2*i] if n >= 2*i heap[i].right = heap...
class Node attr_accessor :key, :parent, :left, :right def initialize(key) @key = key end end n = gets.to_i heap = [] gets.split.map(&:to_i).each{ |i| heap << Node.new(i) } heap.unshift nil (1..n).each do |i| heap[i].parent = heap[i/2] if i > 0 heap[i].left = heap[2*i] if n >= 2*i heap[i].right = heap...
[["-", 8, 736, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 8, 736, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22], ["+", 8, 736, 0, 652, 3, 4, 0, 557, 0, 62]]
4
224
6
n = STDIN.gets.to_i array = STDIN.gets.split.map(&:to_i) array.each_with_idx do |n, idx| printf("node %d: key = %d,", idx + 1, num) printf(" parent key = %d,", array[(idx - 1) / 2]) if idx != 0 printf(" left key = %d,", array[idx * 2 + 1]) if idx * 2 + 1 < array.size printf(" right key = %d,", array[idx * 2 + ...
n = STDIN.gets.to_i array = STDIN.gets.split.map(&:to_i) array.each_with_index do |num, idx| printf("node %d: key = %d,", idx + 1, num) printf(" parent key = %d,", array[(idx - 1) / 2]) if idx != 0 printf(" left key = %d,", array[idx * 2 + 1]) if idx * 2 + 1 < array.size printf(" right key = %d,", array[idx * ...
[["-", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22], ["+", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22], ["-", 0, 493, 0, 652, 196, 737, 54, 758, 0, 22], ["+", 0, 493, 0, 652, 196, 737, 54, 758, 0, 22]]
4
120
4
def parent(i) return i/2 end def left(i) return i*2 end def right(i) return i*2+1 end n=gets.to_i arr=gets.split.map(&:to_i) arr.unshift(nil) (1..n).each do |i| print "node #{i}, key = #{arr[i]}, " if parent(i)>=1 print "parent key = #{arr[parent(i)]}, " end if left(i)<=n print "left key = #{arr[l...
def parent(i) return i/2 end def left(i) return i*2 end def right(i) return i*2+1 end n=gets.to_i arr=gets.split.map(&:to_i) arr.unshift(nil) (1..n).each do |i| print "node #{i}: key = #{arr[i]}, " if parent(i)>=1 print "parent key = #{arr[parent(i)]}, " end if left(i)<=n print "left key = #{arr[l...
[["-", 8, 736, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 8, 736, 0, 652, 3, 4, 0, 557, 0, 6]]
4
150
2
def read_tree(a) def parent(array, index) if(index != 1) " parent key = #{array[index/2]}, " end end def keys(array, index) left = 2*index right = 2*index + 1 if(left < array.length && right < array.length) "left key = #{array[left]}, right key = #{array[right]}, " elsif(left < array.length && ri...
def read_tree(a) def parent(array, index) if(index != 1) "parent key = #{array[index/2]}, " end end def keys(array, index) left = 2*index right = 2*index + 1 if(left < array.length && right < array.length) "left key = #{array[left]}, right key = #{array[right]}, " elsif(left < array.length && rig...
[["-", 8, 736, 0, 121, 64, 749, 0, 557, 0, 6], ["+", 8, 736, 0, 121, 64, 749, 0, 557, 0, 6], ["-", 8, 170, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 8, 170, 0, 652, 3, 4, 0, 557, 0, 6]]
4
211
4
n = gets.to_i heep = gets.split.map(&:to_i) heep.each_with_index{|val, j| i = j + 1 str = "node #{j}: key = #{val}, " str << "parent key = #{heep[i/2-1]}, " if j > 0 str << "left key = #{heep[2*i-1]}, " if 2 * i - 1 < n str << "right key = #{heep[2*i]}, " if 2 * i < n puts str }
n = gets.to_i heep = gets.split.map(&:to_i) heep.each_with_index{|val, j| i = j + 1 str = "node #{i}: key = #{val}, " str << "parent key = #{heep[i/2-1]}, " if j > 0 str << "left key = #{heep[2*i-1]}, " if 2 * i - 1 < n str << "right key = #{heep[2*i]}, " if 2 * i < n puts str }
[["-", 8, 734, 0, 662, 12, 557, 0, 284, 0, 22], ["+", 8, 734, 0, 662, 12, 557, 0, 284, 0, 22]]
4
110
2
n = int(input()) tree = list(map(int, input().split())) for i in range(n) : s = 'node ' + str(i + 1) + ':key = ' + str(tree[i]) if (i > 0) & (i % 2 == 0) : s += ', parent key = ' + str(tree[i // 2 - 1]) elif (i > 0) & (i % 2 == 1): s += ', parent key = ' + str(tree[i // 2]) if i * 2 + ...
n = int(input()) tree = list(map(int, input().split())) for i in range(n) : s = 'node ' + str(i + 1) + ': key = ' + str(tree[i]) if (i > 0) & (i % 2 == 0) : s += ', parent key = ' + str(tree[i // 2 - 1]) elif (i > 0) & (i % 2 == 1): s += ', parent key = ' + str(tree[i // 2]) if i * 2 +...
[["-", 0, 662, 12, 657, 31, 657, 12, 557, 0, 6], ["+", 0, 662, 12, 657, 31, 657, 12, 557, 0, 6]]
5
200
2
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10 ** 9) def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) H=INT() A=LIST()+[None]*(H*2) for i in range(H): node=i+1 key=A[i] ...
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10 ** 9) def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) H=INT() A=LIST()+[None]*(H*2) for i in range(H): node=i+1 key=A[i] ...
[["-", 3, 4, 0, 657, 31, 657, 31, 557, 0, 6], ["+", 3, 4, 0, 657, 31, 657, 31, 557, 0, 6]]
5
271
2
class complete_btree: def __init__(self, vals): self.vals=vals self.index_max = len(self.vals) def check(self, i): assert(i >= 1) assert(i <= self.index_max) def val_at(self, i): self.check(i) return self.vals[i-1] def left_idx(self, i): self.ch...
class complete_btree: def __init__(self, vals): self.vals=vals self.index_max = len(self.vals) def check(self, i): assert(i >= 1) assert(i <= self.index_max) def val_at(self, i): self.check(i) return self.vals[i-1] def left_idx(self, i): self.ch...
[["-", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6], ["+", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6]]
5
360
2
import math n = int(input()) heap = [None] + list(map(int, input().split())) for i, x in enumerate(heap): if i == 0: continue p = math.floor(i / 2) parent = '' if 1 <= p: parent = "parent key = {}, ".format(heap[p]) left = i * 2 l = '' if left <= n: l = 'left key = {}...
import math n = int(input()) heap = [None] + list(map(int, input().split())) for i, x in enumerate(heap): if i == 0: continue p = math.floor(i / 2) parent = '' if 1 <= p: parent = "parent key = {}, ".format(heap[p]) left = i * 2 l = '' if left <= n: l = 'left key = {}...
[["-", 0, 7, 8, 196, 0, 57, 15, 666, 0, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 0, 22]]
5
167
2
n = int(input()) heap = list(map(int, input().split())) for i in range(len(heap)): out = 'node {}: key = {}, '.format(i + 1, heap[i]) parent = (i - 1) // 2 out += 'parent key = {}, '.format(heap[parent]) if parent >= 0 else '' left = (2 * i) + 1 out += 'left key = {}'.format(heap[left]) if left < le...
n = int(input()) heap = list(map(int, input().split())) for i in range(len(heap)): out = 'node {}: key = {}, '.format(i + 1, heap[i]) parent = (i - 1) // 2 out += 'parent key = {}, '.format(heap[parent]) if parent >= 0 else '' left = (2 * i) + 1 out += 'left key = {}, '.format(heap[left]) if left < ...
[["-", 12, 41, 0, 652, 63, 319, 500, 557, 0, 6], ["+", 12, 41, 0, 652, 63, 319, 500, 557, 0, 6]]
5
150
4
if __name__ == '__main__': N = input() heap_array = [int(i) for i in input().split()] for i in range(len(heap_array)): print("node {},: key = {}, ".format(i+1, heap_array[i]), end='') if (i-1)//2 != -1 : print("parent key = {}, ".format(heap_array[(i-1)//2]), end='') if ...
if __name__ == '__main__': N = input() heap_array = [int(i) for i in input().split()] for i in range(len(heap_array)): print("node {}: key = {}, ".format(i+1, heap_array[i]), end='') if (i-1)//2 != -1 : print("parent key = {}, ".format(heap_array[(i-1)//2]), end='') if 2...
[["-", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6], ["+", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6]]
5
176
2
#! -*- coding:utf-8 -*- n = int(input()) data = list(input().split()) data = [int(i) for i in data] for i in range(n): print('node ',i+1,': ',sep = '',end = '') print('key =',data[i],',',sep = '',end = '') if i != 0: print(' parent key = ',data[(i-1)//2],',',sep = '',end = '') if 2*i + 1 ...
#! -*- coding:utf-8 -*- n = int(input()) data = list(input().split()) data = [int(i) for i in data] for i in range(n): print('node ',i+1,':',sep = '',end = '') print(' key = ',data[i],',',sep = '',end = '') if i != 0: print(' parent key = ',data[(i-1)//2],',',sep = '',end = '') if 2*i + 1...
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
5
229
5
n = int(input()) xs = [int(i) for i in input().split()] for i in range(n): ind = i + 1 ret = "node" + str(ind) + ": key = " + str(xs[ind - 1]) if ind != 1: parent = ind // 2 - 1 ret += ", parent key = " + str(xs[parent]) if n > 2 * i + 1: ret += ", left key = " + str(xs[2 * i + 1...
n = int(input()) xs = [int(i) for i in input().split()] for i in range(n): ind = i + 1 ret = "node " + str(ind) + ": key = " + str(xs[ind - 1]) if ind != 1: parent = ind // 2 - 1 ret += ", parent key = " + str(xs[parent]) if n > 2 * i + 1: ret += ", left key = " + str(xs[2 * i + ...
[["-", 12, 657, 31, 657, 31, 657, 31, 557, 0, 6], ["+", 12, 657, 31, 657, 31, 657, 31, 557, 0, 6]]
5
149
2
# coding=utf-8 import math class Tree(): def __init__(self, key): self.root = key class Node(): def __init__(self, id, key): self.id = id self.key = key self.parent = None self.left = None self.right = None def set_status(self, id, key): global node...
# coding=utf-8 import math class Tree(): def __init__(self, key): self.root = key class Node(): def __init__(self, id, key): self.id = id self.key = key self.parent = None self.left = None self.right = None def set_status(self, id, key): global node...
[["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 654], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 655]]
5
319
3
def main(): """ ????????? """ H = int(input().strip()) hkeys = list(map(int,(input().split()))) for i in range(H): txts = [] id = i + 1 txts.append("node {}:key = {},".format(id, hkeys[i])) parent = int(id / 2) if parent != 0: txts.append("parent key ...
def main(): """ ????????? """ H = int(input().strip()) hkeys = list(map(int,(input().split()))) for i in range(H): txts = [] id = i + 1 txts.append("node {}: key = {},".format(id, hkeys[i])) parent = int(id / 2) if parent != 0: txts.append("parent ke...
[["-", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6], ["+", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6]]
5
197
2
# -*- coding: utf-8 -*- if __name__ == '__main__': H = int(input()) A = [None] + [int(i) for i in input().split(" ")] def parent(i): return i // 2 def left(i): return 2*i def right(i): return 2*i + 1 for i in range(1, H+1): print("node {}: key = {}".format(...
# -*- coding: utf-8 -*- if __name__ == '__main__': H = int(input()) A = [None] + [int(i) for i in input().split(" ")] def parent(i): return i // 2 def left(i): return 2*i def right(i): return 2*i + 1 for i in range(1, H+1): print("node {}: key = {},".format...
[["-", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6], ["+", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6]]
5
205
2
input() A=[0]+input().split() H=len(A) for i in range(1,H): print(f'node {i}: key = {A[i]}, {f"parent key = {A[i//2]}, "if i>0 else""}{f"left key = {A[2*i]}, "if 2*i<H else""}{f"right key = {A[2*i+1]}, "if 2*i+1<H else""}')
input() A=[0]+input().split() H=len(A) for i in range(1,H): print(f'node {i}: key = {A[i]}, {f"parent key = {A[i//2]}, "if i>1 else""}{f"left key = {A[2*i]}, "if 2*i<H else""}{f"right key = {A[2*i+1]}, "if 2*i+1<H else""}')
[["-", 0, 557, 0, 284, 205, 41, 0, 666, 0, 612], ["+", 0, 557, 0, 284, 205, 41, 0, 666, 0, 612]]
5
120
2
k=' key = ' input() A=[0]+input().split() H=len(A) for i in range(1,H): print(f'node {i}: key = {A[i]}, {"parent"+k+A[i//2]+" "if i>1 else""}{"left"+k+A[2*i]+" "if 2*i<H else""}{"right"+k+A[2*i+1]+" "if 2*i+1<H else""}')
k=' key = ' input() A=[0]+input().split() H=len(A) for i in range(1,H): print(f'node {i}: key = {A[i]}, {"parent"+k+A[i//2]+", "if i>1 else""}{"left"+k+A[2*i]+", "if 2*i<H else""}{"right"+k+A[2*i+1]+", "if 2*i+1<H else""}')
[["-", 0, 284, 205, 41, 0, 657, 12, 557, 0, 6], ["+", 0, 284, 205, 41, 0, 657, 12, 557, 0, 6]]
5
137
18
import math def make_row(id, heap): s = "node " + str(id) + ": key = " + str(heap[id - 1]) + ", " length = len(heap) if 0 <= math.floor(id // 2) - 1 < length: s += "parent key = " + str(heap[math.floor(id // 2) - 1]) + ", " if 0 <= 2 * id - 1 < length: s += "left key = " + str(heap[2 *...
import math def make_row(id, heap): s = "node " + str(id) + ": key = " + str(heap[id - 1]) + ", " length = len(heap) if 0 <= math.floor(id // 2) - 1 < length: s += "parent key = " + str(heap[math.floor(id // 2) - 1]) + ", " if 0 <= 2 * id - 1 < length: s += "left key = " + str(heap[2 *...
[["-", 12, 652, 3, 4, 0, 206, 206, 657, 12, 612], ["+", 12, 652, 3, 4, 0, 206, 206, 657, 12, 612]]
5
195
2
#include <stdio.h> #include <stdlib.h> int n; int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } void maxHeapify(int a[], int i) { int l, r, largest, tmp; l = left(i); r = right(i); if (i <= n && a[l] > a[i]) largest = l; else largest = i; if (r <= n && a[r] > a[largest]) ...
#include <stdio.h> #include <stdlib.h> int n; int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } void maxHeapify(int a[], int i) { int l, r, largest, tmp; l = left(i); r = right(i); if (l <= n && a[l] > a[i]) largest = l; else largest = i; if (r <= n && a[r] > a[largest]) ...
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 31, 22]]
0
297
2
#include <stdio.h> int H[500001], size; int left(int l) { return 2 * l; } int right(int r) { return 2 * r + 1; } void maxheapify(int h[], int i) { int largest, ln, rn, an; ln = left(i); rn = right(i); if (ln <= size && h[ln] > h[i]) { largest = ln; } else largest = i; if (rn <= size && h[rn...
#include <stdio.h> int H[500001], size; int left(int l) { return 2 * l; } int right(int r) { return 2 * r + 1; } void maxheapify(int h[], int i) { int largest, ln, rn, an; ln = left(i); rn = right(i); if (ln <= size && h[ln] > h[i]) { largest = ln; } else largest = i; if (rn <= size && h[rn...
[["-", 0, 7, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
0
287
5
#include <stdio.h> #define MAX 500000 void maxHeapify(int *, int, int); void buildMaxHeap(int *, int); int main() { int A[MAX], i, h; scanf("%d", &h); for (i = 1; i <= h; i++) { scanf("%d", &A[i]); } buildMaxHeap(A, h); for (i = 1; i <= h; i++) { printf(" %d", A[i]); } printf("\n"); retu...
#include <stdio.h> #define MAX 500000 void maxHeapify(int *, int, int); void buildMaxHeap(int *, int); int main() { int A[MAX], i, h; scanf("%d", &h); for (i = 1; i <= h; i++) { scanf("%d", &A[i]); } buildMaxHeap(A, h); for (i = 1; i <= h; i++) { printf(" %d", A[i]); } printf("\n"); retu...
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 31, 22]]
0
288
2
#include <ctype.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> //============================================================================ #define pred(x) ((x)-1) #define succ(x) ((x) + 1) //============================================================================ #define PARENT(...
#include <ctype.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> //============================================================================ #define pred(x) ((x)-1) #define succ(x) ((x) + 1) //============================================================================ #define PARENT(...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18]]
0
612
2
#include <stdio.h> #define SIZE 500000 int heap[SIZE]; void maxHeapify(int i, int n) { int l = 2 * i; int r = 2 * i + 1; int largest = i; if (l < n && heap[l] > heap[i]) { largest = l; } if (r < n && heap[r] > heap[largest]) { largest = r; } if (largest != i) { int temp = heap[i]; hea...
#include <stdio.h> #define SIZE 500000 int heap[SIZE]; void maxHeapify(int i, int n) { int l = 2 * i; int r = 2 * i + 1; int largest = i; if (l <= n && heap[l] > heap[i]) { largest = l; } if (r <= n && heap[r] > heap[largest]) { largest = r; } if (largest != i) { int temp = heap[i]; h...
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 17, 18], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 19]]
0
365
4
#include <stdio.h> #define N 500001 int n; int left(i) { return 2 * i; } int right(i) { return 2 * i + 1; } void maxHeapify(int *H, int i) { int l = left(i); int r = right(i); int largest; int tmp; if (i <= n && H[l] > H[i]) largest = l; else largest = i; if (i <= n && H[r] > H[largest]) ...
#include <stdio.h> #define N 500001 int n; int left(i) { return 2 * i; } int right(i) { return 2 * i + 1; } void maxHeapify(int *H, int i) { int l = left(i); int r = right(i); int largest; int tmp; if (i <= n / 2 && H[l] > H[i]) largest = l; else largest = i; if (i <= n / 2 && H[r] > H[larges...
[["+", 15, 23, 0, 16, 31, 16, 12, 16, 17, 85], ["+", 15, 23, 0, 16, 31, 16, 12, 16, 12, 13], ["+", 8, 9, 0, 7, 10, 11, 12, 16, 17, 85], ["+", 8, 9, 0, 7, 10, 11, 12, 16, 12, 13]]
0
277
6
#include <stdio.h> #define MAX 500000 int H, A[MAX + 1]; void swap(int *a, int *b) { int temp; temp = *a; *a = *b; *b = temp; } int Left(int i) { return 2 * i; } int Right(int i) { return 2 * i + 1; } void maxH(int i) { int l, r, larg; l = Left(i); r = Right(i); if (l <= H && A[l] > A[i]) larg =...
#include <stdio.h> #define MAX 500000 int H, A[MAX + 1]; void swap(int *a, int *b) { int temp; temp = *a; *a = *b; *b = temp; } int Left(int i) { return 2 * i; } int Right(int i) { return 2 * i + 1; } void maxH(int i) { int l, r, larg; l = Left(i); r = Right(i); if (l <= H && A[l] > A[i]) larg =...
[["-", 8, 9, 0, 57, 64, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 12, 22]]
0
277
2
#include <stdio.h> #define MAX 2000000 int A[MAX + 1], H; void maxHeapify(int i) { int l, r, largest, a; l = i * 2; r = i * 2 + 1; // ????????????????????????????????§???????????§????????????????????¶ if (l <= H && A[l] > A[i]) largest = l; else largest = i; if (r <= H && A[r] > A[largest]) ...
#include <stdio.h> #define MAX 2000000 int A[MAX + 1], H; void maxHeapify(int i) { int l, r, largest, a; l = i * 2; r = i * 2 + 1; // ????????????????????????????????§???????????§????????????????????¶ if (l <= H && A[l] > A[i]) largest = l; else largest = i; if (r <= H && A[r] > A[largest]) ...
[["-", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
231
2
#include <stdio.h> #define H 20000000 int maxHeapify(int *, int); int x; int main() { int i, A[H]; scanf("%d", &x); for (i = 1; i <= x; i++) scanf("%d", &A[i]); for (i = x / 2; i >= 1; i--) { maxHeapify(A, i); } for (i = 1; i <= x; i++) { printf(" %d", A[i]); } printf("\n"); return...
#include <stdio.h> #define H 500000 int maxHeapify(int *, int); int x; int main() { int i, A[H]; scanf("%d", &x); for (i = 1; i <= x; i++) scanf("%d", &A[i]); for (i = x / 2; i >= 1; i--) { maxHeapify(A, i); } for (i = 1; i <= x; i++) { printf(" %d", A[i]); } printf("\n"); return 0...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
0
251
2
#include <stdio.h> #define H 500001 int n; int maxHeapify(int A[], int i) { int l, r, largest, temp; l = 2 * i; r = 2 * i + 1; if (l <= H && A[l] > A[i]) largest = l; else largest = i; if (r <= H && A[r] > A[largest]) largest = r; if (largest != i) { temp = A[i]; A[i] = A[largest]; ...
#include <stdio.h> #define H 500001 int n; int maxHeapify(int A[], int i) { int l, r, largest, temp; l = 2 * i; r = 2 * i + 1; if (l <= n && A[l] > A[i]) largest = l; else largest = i; if (r <= n && A[r] > A[largest]) largest = r; if (largest != i) { temp = A[i]; A[i] = A[largest]; ...
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 12, 22]]
0
257
4
#include <stdio.h> #define NIL -1 int n; int getleft(int i) { i *= 2; if (i > n) return NIL; else return i; } int getright(int i) { i = 2 * i + 1; if (i > n) return NIL; else return i; } void maxHeapify(int A[], int i) { int l, r, largest, temp; l = getleft(i); r = getright(i); ...
#include <stdio.h> #define NIL 500009 int n; int getleft(int i) { i *= 2; if (i > n) return NIL; else return i; } int getright(int i) { i = 2 * i + 1; if (i > n) return NIL; else return i; } void maxHeapify(int A[], int i) { int l, r, largest, temp; l = getleft(i); r = getright(i)...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
0
319
4
#define _CRT_SECURE_NO_WARNINGS #include <limits.h> #include <stdio.h> #include <stdlib.h> int A[50000], n; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } void maxHeapify(int i) { int largest, tmp; int l = left(i); int r = right(i); if (l <= n &&...
#define _CRT_SECURE_NO_WARNINGS #include <limits.h> #include <stdio.h> #include <stdlib.h> int A[500001], n; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } void maxHeapify(int i) { int largest, tmp; int l = left(i); int r = right(i); if (l <= n &...
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13]]
0
336
2
#include <stdio.h> #define MAX 500005 int heap[MAX]; int size; int parent(int); int left(int); int right(int); void maxHeapify(int); void builtMaxHeap(); int main() { int i, n; scanf("%d", &n); size = n; for (i = 1; i <= n; i++) scanf("%d", heap[i]); builtMaxHeap(); for (i = 1; i <= n; i++) pr...
#include <stdio.h> #define MAX 500005 int heap[MAX]; int size; int parent(int); int left(int); int right(int); void maxHeapify(int); void builtMaxHeap(void); int main() { int i, n; scanf("%d", &n); size = n; for (i = 1; i <= n; i++) scanf("%d", &heap[i]); builtMaxHeap(); for (i = 1; i <= n; i++) ...
[["+", 0, 43, 49, 53, 54, 55, 0, 56, 39, 40], ["+", 8, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
0
315
2
#include <math.h> #include <stdio.h> #define N 500000 int parent(int); int left(int); int right(int); void buildMaxHeap(int *); void maxHeapify(int *, int); int n; main() { int i, *k[N]; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", k + i); buildMaxHeap(k); for (i = 1; i <= n; i++) prin...
#include <math.h> #include <stdio.h> #define N 500000 int parent(int); int left(int); int right(int); void buildMaxHeap(int *); void maxHeapify(int *, int); int n; main() { int i, k[N]; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", k + i); buildMaxHeap(k); for (i = 1; i <= n; i++) print...
[["-", 0, 30, 0, 9, 0, 43, 49, 84, 0, 48], ["-", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
331
3
#include <stdio.h> #define N 500004 int h[N], n; int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } void maxheapify(i) { int largest = 0, tmp; int l, r; l = left(i); r = right(i); if (i <= n && h[l] > h[i]) { largest = l; } else largest = i; if (r <= n && h[r] > h[largest...
#include <stdio.h> #define N 500004 int h[N], n; int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } void maxheapify(i) { int largest = 0, tmp; int l, r; l = left(i); r = right(i); if (l <= n && h[l] > h[i]) { largest = l; } else largest = i; if (r <= n && h[r] > h[largest...
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 31, 22], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 20], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 47], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13]]
0
283
6
#include <algorithm> #include <iostream> using namespace std; const int MAX = 2000000; int H, A[MAX + 1]; void maxHeapify(int i) { int l, r, largest; l = 2 * i; r = 2 * i + 1; if (l <= H && A[l] > A[i]) { largest = l; } else { largest = i; } if (r <= H && A[r] > A[largest]) { largest = r;...
#include <algorithm> #include <iostream> using namespace std; const int MAX = 2000000; int H, A[MAX + 1]; void maxHeapify(int i) { int l, r, largest; l = 2 * i; r = 2 * i + 1; if (l <= H && A[l] > A[i]) { largest = l; } else { largest = i; } if (r <= H && A[r] > A[largest]) { largest = r;...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
1
220
2
#include <iostream> using namespace std; int A[500001], n; void maxHeapify(int i) { int l, r, largest, tmp; l = i * 2; r = i * 2 + 1; if (l <= n && A[l] > A[i]) largest = l; else largest = i; if (r <= n && A[r] > A[largest]) largest = r; if (largest != i) { tmp = A[i], A[i] = A[largest]...
#include <iostream> using namespace std; int A[500001], n; void maxHeapify(int i) { int l, r, largest, tmp; l = i * 2; r = i * 2 + 1; if (l <= n && A[l] > A[i]) largest = l; else largest = i; if (r <= n && A[r] > A[largest]) largest = r; if (largest != i) { tmp = A[i], A[i] = A[largest]...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
1
221
2
#include <iostream> using namespace std; const int MAX = 500000; int A[MAX + 1]; int H; void maxHeapify(int i) { int largest; int l = i * 2; int r = i * 2 + 1; if (i <= H && A[l] > A[i]) { largest = l; } else { largest = i; } if (i <= H && A[r] > A[largest]) largest = r; if (largest != i...
#include <iostream> using namespace std; const int MAX = 500000; int A[MAX + 1]; int H; void maxHeapify(int i) { int largest; int l = i * 2; int r = i * 2 + 1; if (l <= H && A[l] > A[i]) { largest = l; } else { largest = i; } if (r <= H && A[r] > A[largest]) largest = r; if (largest != i...
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22]]
1
223
4
#include <iostream> using namespace std; #define MAX 2000000 int H, A[MAX + 1]; void maxHeapify(int i) { int l, r, largest; l = 2 * i; r = 2 * i + 1; //????????????????????????????????????????????????????????§????????? if (l <= H && A[l] > A[i]) largest = l; else largest = i; if (r <= H && A[r]...
#include <iostream> using namespace std; #define MAX 2000000 int H, A[MAX + 1]; void maxHeapify(int i) { int l, r, largest; l = 2 * i; r = 2 * i + 1; //????????????????????????????????????????????????????????§????????? if (l <= H && A[l] > A[i]) largest = l; else largest = i; if (r <= H && A[r]...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
1
201
2
#include <iostream> using namespace std; #define MAX 500005 int H, A[MAX + 1]; void maxHeap(int i) { int l, r, large; l = 2 * i; r = 2 * i + 1; if (l <= H && A[l] > A[i]) { large = l; } else { large = i; } if (r <= H && A[r] > A[i]) { large = r; } if (large != i) { swap(A[large], A[...
#include <iostream> using namespace std; #define MAX 500005 int H, A[MAX + 1]; void maxHeap(int i) { int l, r, large; l = 2 * i; r = 2 * i + 1; if (l <= H && A[l] > A[i]) { large = l; } else { large = i; } if (r <= H && A[r] > A[large]) { large = r; } if (large != i) { swap(A[large]...
[["-", 51, 16, 12, 16, 12, 69, 341, 342, 0, 22], ["+", 51, 16, 12, 16, 12, 69, 341, 342, 0, 22]]
1
211
2
#include <stdio.h> #define MAX 500000 int N; int H[MAX]; int getLeft(int i) { return 2 * i + 1; } int getRight(int i) { return 2 * i + 2; } int getParent(int i) { return (i - 1) / 2; } void swap(int i, int j) { int temp = H[i]; H[i] = H[j]; H[j] = temp; } void heapify(int i) { while (i < N) { int max_idx ...
#include <stdio.h> #define MAX 500000 int N; int H[MAX]; int getLeft(int i) { return 2 * i + 1; } int getRight(int i) { return 2 * i + 2; } int getParent(int i) { return (i - 1) / 2; } void swap(int i, int j) { int temp = H[i]; H[i] = H[j]; H[j] = temp; } void heapify(int i) { while (i < N) { int max_idx ...
[["-", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
311
2
#include <bits/stdc++.h> using namespace std; #define MAX 2000000 int H, A[MAX + 1]; void maxHeapify(int i) { int l, r, largest; l = 2 * i; r = 2 * i + 1; //??????????????????????????????????????????????????§????????????????????¶ if (l <= H && A[l] > A[i]) largest = l; else largest = i; if (r ...
#include <bits/stdc++.h> using namespace std; #define MAX 2000000 int H, A[MAX + 1]; void maxHeapify(int i) { int l, r, largest; l = 2 * i; r = 2 * i + 1; //??????????????????????????????????????????????????§????????????????????¶ if (l <= H && A[l] > A[i]) largest = l; else largest = i; if (r ...
[["-", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
1
220
1
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPP(i, n) for (int i = 1; i < n; i++) #define REPR(i, n) for (int i = n; i >= 1; i--) #define IFY 2000000000 #define MAX 500000 #define NIL -1 using namespace std; int H, A[MAX + 1]; void maxheapify(int i) { int l, r, largest; l = 2 * i...
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPP(i, n) for (int i = 1; i <= n; i++) #define REPR(i, n) for (int i = n; i >= 1; i--) #define IFY 2000000000 #define MAX 500000 #define NIL -1 using namespace std; int H, A[MAX + 1]; void maxheapify(int i) { int l, r, largest; l = 2 * ...
[["-", 36, 36, 36, 36, 0, 30, 0, 112, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 112, 51, 59]]
1
228
2
#include <iostream> using namespace std; #define MAX 2000000 int gHeap[MAX + 1], gSize; void maxHeapify(int i) { int left, right, largest; left = 2 * i; right = 2 * i + 1; // 左の子、自分、右の子で値が最大のノードを選択 if (left <= gSize && gHeap[left] > gHeap[i]) { largest = left; } else { largest = i; } // 右の子と比...
#include <iostream> using namespace std; #define MAX 2000000 int gHeap[MAX + 1], gSize; void maxHeapify(int i) { int left, right, largest; left = 2 * i; right = 2 * i + 1; // 左の子、自分、右の子で値が最大のノードを選択 if (left <= gSize && gHeap[left] > gHeap[i]) { largest = left; } else { largest = i; } // 右の子と比...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 20]]
1
211
2
#include <iostream> using namespace std; #define MAX 2000000 int H; int A[MAX + 1]; void maxHeapify(int i) { int largest, right, left; left = 2 * i; right = 2 * i + 1; if (left <= H && A[left] > A[i]) largest = left; else largest = i; if (right <= H && A[right] > A[i]) largest = right; if (...
#include <iostream> using namespace std; #define MAX 2000000 int H; int A[MAX + 1]; void maxHeapify(int i) { int largest, right, left; left = 2 * i; right = 2 * i + 1; if (left <= H && A[left] > A[i]) largest = left; else largest = i; if (right <= H && A[right] > A[largest]) largest = right; ...
[["-", 51, 16, 12, 16, 12, 69, 341, 342, 0, 22], ["+", 51, 16, 12, 16, 12, 69, 341, 342, 0, 22]]
1
206
2
#include <cstdio> #include <iostream> #define MAX 2000000 using namespace std; int H, a[MAX + 1]; void max(int i) { int l, r, large; l = 2 * i; r = 2 * i + 1; if (l <= H && a[l] > a[i]) large = 1; else large = i; if (r <= H && a[r] > a[large]) large = r; if (large != i) { swap(a[i], a[larg...
#include <cstdio> #include <iostream> #define MAX 2000000 using namespace std; int H, a[MAX + 1]; void max(int i) { int l, r, large; l = 2 * i; r = 2 * i + 1; if (l <= H && a[l] > a[i]) large = l; else large = i; if (r <= H && a[r] > a[large]) large = r; if (large != i) { swap(a[i], a[larg...
[["-", 8, 9, 0, 57, 64, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 12, 22]]
1
205
2
CMD=0 VAL=1 class Node attr_accessor :value,:left,:right def initialize (value) @value = value @left = nil @right = nil end def insert (value) if value < @value if @left.nil? @left = Node.new(value) else @left.insert(value) end else if @right.nil? ...
CMD=0 VAL=1 class Node attr_accessor :value,:left,:right def initialize (value) @value = value @left = nil @right = nil end def insert (value) if value < @value if @left.nil? @left = Node.new(value) else @left.insert(value) end else if @right.nil? ...
[["+", 8, 736, 0, 652, 3, 4, 0, 557, 0, 6], ["-", 8, 736, 0, 652, 3, 4, 0, 557, 0, 6], ["-", 0, 735, 8, 736, 0, 745, 8, 652, 735, 22], ["+", 0, 735, 8, 736, 0, 745, 8, 652, 735, 22]]
4
240
8
class Node attr_reader :value def initialize(value) @value = value @left = nil @right = nil end def insert(value) if value < @value if @left @left.insert(value) else @left = Node.new(value) end else if @right @right.insert(value) else ...
class Node attr_reader :value def initialize(value) @value = value @left = nil @right = nil end def insert(value) if value < @value if @left @left.insert(value) else @left = Node.new(value) end else if @right @right.insert(value) else ...
[["-", 0, 173, 0, 763, 374, 374, 0, 575, 0, 6], ["+", 0, 173, 0, 763, 374, 374, 0, 575, 0, 6], ["+", 0, 763, 8, 749, 0, 662, 12, 652, 17, 131], ["+", 0, 763, 8, 749, 0, 662, 12, 652, 735, 22]]
4
229
4
class binaryTree: def __init__(self,key,p=None,l=None,r=None): self.key = key self.p = p self.l = l self.r = r N = int(input()) treelist = [list(input().split()) for i in range(N)] root = None def inorder(root): x = root if x == None: return inorder(x.l) ...
class binaryTree: def __init__(self,key,p=None,l=None,r=None): self.key = key self.p = p self.l = l self.r = r N = int(input()) treelist = [list(input().split()) for i in range(N)] root = None def inorder(root): x = root if x == None: return inorder(x.l) ...
[["-", 12, 652, 3, 4, 0, 658, 0, 659, 12, 22], ["+", 12, 652, 3, 4, 0, 658, 0, 659, 12, 22]]
5
343
2
class BinaryTree: from io import StringIO class Node: def __init__(self, key): self.key = key self.left = None self.right = None self.parent = None def __init__(self): self.root = None self.output = StringIO() def insert(se...
from io import StringIO class BinaryTree: class Node: def __init__(self, key): self.key = key self.left = None self.right = None self.parent = None def __init__(self): self.root = None self.output = StringIO() def insert(self, key)...
[["-", 36, 36, 36, 36, 0, 656, 0, 682, 0, 269], ["-", 36, 36, 36, 36, 0, 656, 0, 682, 141, 22], ["-", 36, 36, 36, 36, 0, 656, 0, 682, 0, 102], ["+", 36, 36, 36, 36, 0, 656, 0, 682, 0, 269], ["+", 36, 36, 36, 36, 0, 656, 0, 682, 141, 22], ["+", 36, 36, 36, 36, 0, 656, 0, 682, 0, 102]]
5
430
6
import re class Node: key = None left = None right = None def __init__(self, k): self.key = k class BST: root = None def insert(self, k): x = self.root y = None z = Node(k) while x is not None: y = x if z.key < y.key: x = x.left elif y.key < z.key: x =...
import re class Node: key = None left = None right = None def __init__(self, k): self.key = k class BST: root = None def insert(self, k): x = self.root y = None z = Node(k) while x is not None: y = x if z.key < y.key: x = x.left elif y.key < z.key: x =...
[["-", 0, 657, 12, 652, 3, 4, 0, 652, 63, 22], ["-", 12, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 3, 4, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24]]
5
309
4
import sys class Node(): def __init__(self,key): self.key = key self.left = None self.right = None def insert(t, z): y = None x = t while x is not None: y = x if z.key < x.key: x = x.left else: x = x.right if y is None: ...
import sys class Node(): def __init__(self,key): self.key = key self.left = None self.right = None def insert(t, z): y = None x = t while x is not None: y = x if z.key < x.key: x = x.left else: x = x.right if y is None: ...
[["-", 8, 196, 0, 57, 15, 666, 0, 206, 51, 22], ["+", 8, 196, 0, 57, 15, 666, 0, 206, 51, 22]]
5
338
2
def insert(r, n): if 0 == len(T): T[n] = [None, None] else: if n < r: left = T[r][0] if left == None: T[r][0] = n T[n] = [None, None] else: insert(left, n) if r < n: right = T[r][1] ...
def insert(r, n): if 0 == len(T): T[n] = [None, None] else: if n < r: left = T[r][0] if left == None: T[r][0] = n T[n] = [None, None] else: insert(left, n) if r < n: right = T[r][1] ...
[["-", 64, 196, 0, 1, 0, 677, 12, 652, 63, 22], ["+", 64, 196, 0, 1, 0, 677, 12, 652, 63, 22]]
5
326
4