import java.util.HashMap; import java.util.LinkedList; import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextInt()) { // 注意 while 处理多个 case int n = in.nextInt(); int[]arr = new int[n]; int[]pre_sum = new int[n + 1]; int[]act = new int[n + 1]; for (int i = 1; i <= n; i++) { arr[i - 1] = in.nextInt(); pre_sum[i] = pre_sum[i - 1] + arr[i - 1]; if (arr[i - 1] > 0) { act[i] = act[i - 1] + 1; } else { act[i] = act[i - 1]; } } int ans = 0; LinkedList<Integer>queue = new LinkedList<>(); //双层循环枚举+前缀和会超时,分两次可以通过所有测试用例 for (int i = 0; i < n - 2; i++) { if (pre_sum[i + 1] * 2 == pre_sum[n] - pre_sum[i + 1] && act[i + 1] > 0 && act[n] - act[i + 1] > 0) { queue.add(i); } } //第二次拆分 while (!queue.isEmpty()) { int start = queue.pop(); for (int j = start + 1; j < n - 1; j++) { if (pre_sum[j + 1] - pre_sum[start + 1] == pre_sum[n] - pre_sum[j + 1] && act[j + 1] - act[start + 1] > 0 && act[n] - act[j + 1] > 0) { ans++; } } } System.out.println(ans); } } }