zoukankan      html  css  js  c++  java
  • Good array (perfect)

    Description


    Smart likes to use arrays. Today, he needs your help to complete a difficult task.
    If for each non-empty sub-array of the array (A) (a sub-array is an array consisting of several consecutive elements selected from the value (A)), if the sum of all the elements of the sub-array is not equal to zero, it is called "Perfect Array". For example, the array ({−1,2,−3}) is "Perfect Array" because all its sub-arrays ({−1}), ({− 1, 2}) , ({− 1, 2, -3}), ({2}), ({2, -3}), and the sum of the elements of ({-3}) are all non-zero. However, the array ({−1, 2, −1, −3}) is not "Perfect Array" because the elements of its subarray ({−1, 2, −1}) The sum is equal to 0.
    Your task is to help Smart calculate the number of "Perfect Array" in the non-empty sub-array of (A) for a given array (A).

    Format


    Input

    The first line contains an integer (n), which represents the length of the array (A).
    The second line contains (n) integers (A_1, A_2, cdots, A_n) for the elements of the array (A).

    Output

    Only one line of the output contains an integer, indicating that the non-empty sub-array of the array (A) is the number of "Perfect Array".

    Sample


    Input

    3
    1 2 -3
    

    Output

    5
    

    Sample Explanation

    Sub-array ({−1}) of array ({1, 2, -3}), ({− 1, 2}), ({− 1, 2, -3}), ({2}), ({2, -3}), ({-3}) is "Perfect Array", but the sub-array ({1, 2, −3}) is not "Perfect Array".

    Hint


    (50\%) data: (n le 1000);
    Data for (100\%): (1 le n le 2 imes 10^5), (-10^9 le A_i le 10^9).

    Sample Code


    Code is not available!
    
  • 相关阅读:
    STM32f469I discovery烧写demo例程
    dsp5509的中断系统
    DSP5509之采样定理
    DSP5509开发之FPGA接口
    mongodb学习之:安全和认证
    mongodb学习之:GridFS
    tornado之异步web服务一
    mongodb学习之:数据库命令以及固定集合
    docker: Dockerfile命令介绍
    mongodb学习之:聚合
  • 原文地址:https://www.cnblogs.com/jiupinzhimaguan/p/13812563.html
Copyright © 2011-2022 走看看