Пример #1
0
        public void Test1()
        {
            var t = new BinaryIndexedTree(4);

            t.Update(0, 1);
            t.Update(3, 4);
            t.Query(0, 3).Should().Be(5);
            t.Query(2).Should().Be(1);
            t.Query(1, 3).Should().Be(4);
        }
Пример #2
0
        public void BIT_Tests()
        {
            List <int> list = new List <int> {
                1, 7, 3, 0, 5, 8, 3, 2, 6, 2, 1, 1, 4, 5
            };
            BinaryIndexedTree bit = new BinaryIndexedTree(list);

            Assert.IsNotNull(bit);
            Assert.AreEqual(43, bit.SumTo(12));
            Assert.AreEqual(27, bit.SumTo(6));
            Assert.AreEqual(23, bit.SumRange(1, 5));

            bit.Update(4, 2);

            Assert.AreEqual(45, bit.SumTo(12));
            Assert.AreEqual(29, bit.SumTo(6));
            Assert.AreEqual(25, bit.SumRange(1, 5));
        }