public void Peek_ValidParamsPassed_Success() { IPriorityQueue <int> priorityQueue = new BinaryHeapPriorityQueue <int>(5, (x, y) => - x.CompareTo(y)); priorityQueue.Insert(5); priorityQueue.Insert(4); priorityQueue.Insert(3); priorityQueue.Insert(2); priorityQueue.Insert(1); var v1 = priorityQueue.Peek(); Assert.AreEqual(v1, 1); }
public void Solve() { var n = sc.Integer(); var q = sc.Integer(); var a = new List <long>() { n }; for (int i = 0; i < q; i++) { a.Add(sc.Long()); } a.Reverse(); var A = new BinaryHeapPriorityQueue(); var last = -1L; foreach (var x in a) { if (A.Count == 0) { A.Enqueue(new KeyValuePair <Number, Number>(x, 1)); } else { if (last <= x) { continue; } while (A.Any()) { if (A.Peek().Key <= x) { break; } var y = A.Dequeue(); var l = y.Key; var v = y.Value; if (A.Any() && A.Peek().Key == l) { var z = A.Dequeue(); v += z.Value; } var k = l / x; A.Enqueue(new KeyValuePair <Number, Number>(x, k * v)); if (l % x != 0) { A.Enqueue(new KeyValuePair <Number, Number>(l % x, v)); } } } last = x; } var ans = new long[n + 1]; while (A.Any()) { var p = A.Dequeue(); ans[p.Key] += p.Value; } for (int i = n - 1; i >= 0; i--) { ans[i] += ans[i + 1]; } for (int i = 0; i < n; i++) { IO.Printer.Out.WriteLine(ans[i + 1]); } }