博客
关于我
一维差分小总结
阅读量:369 次
发布时间:2019-03-04

本文共 1480 字,大约阅读时间需要 4 分钟。

????????????????????????????????????????????????????????????????????

????

  • ????????????????????????????????????(l, r)???????????1???l???1???r+1?
  • ????????????????????????????????????????????
  • ??????????????????????????????????????????????????
  • ???????????????????????????????????
  • ????

    def main():    import sys    input = sys.stdin.read    data = input().split()    idx = 0    n = int(data[idx])    idx += 1    m = int(data[idx])    idx += 1        queries = []    for _ in range(m):        l = int(data[idx])        idx += 1        r = int(data[idx])        idx += 1        queries.append((l, r))        diff = [0] * (n + 2)    for l, r in queries:        diff[l] += 1        if r + 1 <= n:            diff[r + 1] -= 1        freq = [0] * (n + 1)    for i in range(1, n + 1):        freq[i] = diff[i]        freq.sort(reverse=True)        a = [0] * (n + 1)    current = n    for i in range(1, n + 1):        if freq[i] == 0:            a[i] = 0        else:            a[i] = current            current -= 1        pre = [0] * (n + 1)    for i in range(1, n + 1):        pre[i] = pre[i - 1] + a[i]        total = 0    for l, r in queries:        total += pre[r] - pre[l - 1]        print(total)if __name__ == "__main__":    main()

    ????

  • ???????sys.stdin.read?????????????n?m?
  • ?????????????????????????
  • ?????????????????????????
  • ????????????????????????????????????
  • ????????????????????????
  • ???????????????????????
  • ?????????????????????????
  • ????????????????????????????????????????????

    转载地址:http://iryg.baihongyu.com/

    你可能感兴趣的文章
    Netty工作笔记0084---通过自定义协议解决粘包拆包问题2
    查看>>
    Netty常见组件二
    查看>>
    netty底层源码探究:启动流程;EventLoop中的selector、线程、任务队列;监听处理accept、read事件流程;
    查看>>
    Netty核心模块组件
    查看>>
    Netty框架的服务端开发中创建EventLoopGroup对象时线程数量源码解析
    查看>>
    Netty源码—2.Reactor线程模型一
    查看>>
    Netty源码—4.客户端接入流程一
    查看>>
    Netty源码—4.客户端接入流程二
    查看>>
    Netty源码—5.Pipeline和Handler一
    查看>>
    Netty源码—6.ByteBuf原理二
    查看>>
    Netty源码—7.ByteBuf原理三
    查看>>
    Netty源码—7.ByteBuf原理四
    查看>>
    Netty源码—8.编解码原理二
    查看>>
    Netty源码解读
    查看>>
    Netty的Socket编程详解-搭建服务端与客户端并进行数据传输
    查看>>
    Netty相关
    查看>>
    Network Dissection:Quantifying Interpretability of Deep Visual Representations(深层视觉表征的量化解释)
    查看>>
    Network Sniffer and Connection Analyzer
    查看>>
    Net与Flex入门
    查看>>
    net包之IPConn
    查看>>