zoukankan      html  css  js  c++  java
  • [CodeForces] The Number Of Good Substrings Review

    Problem

    Key idea:

    1. for any substring s, if we can do not consider padding prefix 0s, its decimal value is always >= its length.

    2. Appending a binary digit means multiply a number by 2 (and plus 1 if appending 1). This will double the required substring length in order to make its length equal to its decimal value.

    3. N <= 2 * 10^5, so if we ignore leading 0s, we do not need to consider substrings with length >= 19, because 2^18 > 2 * 10^5. 

    Solution:  Fix the highest bit 1 of a substring, then append 1 more bit to get a new value v, if the current length is the same with v, add 1 to ans. Otherwise check if there are v - len preceeding 0s. To speed this up, precompute a zero prefix sum array. For each fixed highest bit 1, we append at most 18 bits. Do this for each 1 in s.

    The runtime is O(N + N * 18)

  • 相关阅读:
    ARC管理内存(一)
    懒加载lazyload
    View的封装
    Plist文件与数据解析
    ubuntu16.04 安装python3.6
    ubuntu16.04 安装 wxPython方法
    第三章
    第二章
    协方差的意义
    内存区--Java
  • 原文地址:https://www.cnblogs.com/lz87/p/15813159.html
Copyright © 2011-2022 走看看