示例#1
0
        public long Query(long l, long r)
        {
            if (r <= l)
            {
                return(long.MinValue);
            }
            var shiftbit = Max(0, LIB_BitUtil.MSB(r - l - 1) - 1);
            var tgtdat   = dat[shiftbit];

            return(Max(tgtdat[l], tgtdat[r - (1 << shiftbit)]));
        }
示例#2
0
 public bool this[int idx]
 {
     [MethodImpl(MethodImplOptions.AggressiveInlining)]
     get { return(LIB_BitUtil.IsSet(ary[idx >> 6], idx & 63)); }
     [MethodImpl(MethodImplOptions.AggressiveInlining)]
     set
     {
         if (value)
         {
             ary[idx >> 6] |= LIB_BitUtil.BitMask[idx & 63];
         }
         else
         {
             ary[idx >> 6] &= ~LIB_BitUtil.BitMask[idx & 63];
         }
     }
 }
示例#3
0
        public LIB_SparseTableMax(IEnumerable <long> initArray)
        {
            var ary = initArray.ToArray();
            var n   = ary.Length;

            dat    = new long[Max(1, LIB_BitUtil.MSB(n - 1))][];
            dat[0] = ary;
            var len = 1;

            for (var k = 1; k < dat.Length; ++k)
            {
                var orgdat = dat[k - 1];
                var tgtdat = dat[k] = new long[n];
                for (var i = 0; i < n - len; ++i)
                {
                    tgtdat[i] = Max(orgdat[i], orgdat[i + len]);
                }
                len <<= 1;
            }
        }