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!
    
  • 相关阅读:
    Java集合类
    打开Eclipse报错
    FusionWidgets之AngularGauge图
    OLAP 大表和小表并行hash join
    分页SQL模板
    全表扫描分页
    Java中的a++和++a的区别
    JAVA中线程同步方法
    final、finally和finalize的区别
    HashMap和Hashtable的异同点
  • 原文地址:https://www.cnblogs.com/jiupinzhimaguan/p/13812563.html
Copyright © 2011-2022 走看看