CF771E.Bear and Rectangle Strips

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Limak has a grid that consists of 2 rows and n columns. The j-th cell in the i-th row contains an integer t__i, j which can be positive, negative or zero.

A non-empty rectangle of cells is called nice if and only if the sum of numbers in its cells is equal to 0.

Limak wants to choose some nice rectangles and give them to his friends, as gifts. No two chosen rectangles should share a cell. What is the maximum possible number of nice rectangles Limak can choose?

Limak 有一个由 2 行 nn 列组成的网格。第 ii 行第 jj 列的单元格中包含一个整数 ti,jt_{i,j},该整数可以为正、负或零。

一个非空的单元格矩形被称为“好矩形”(nice),当且仅当其所有单元格中数字之和等于 0。

Limak 想要选择若干个好矩形作为礼物送给朋友。任意两个被选中的矩形不能共享任何一个单元格。Limak 最多能选出多少个好矩形?

输入格式

The first line of the input contains an integer n (1 ≤ n ≤ 300 000) — the number of columns in the grid.

The next two lines contain numbers in the grid. The i-th of those two lines contains n integers t__i, 1, t__i, 2, ..., t__i, n ( - 109 ≤ t__i, j ≤ 109).

输入的第一行包含一个整数 nn(1≤n≤300 0001 \leq n \leq 300\,000)—— 表示网格的列数。

接下来两行包含网格中的数字。其中第 ii 行(i=1,2i = 1, 2)包含 nn 个整数 ti,1, ti,2, …, ti,nt_{i,1},\ t_{i,2},\ \dots,\ t_{i,n}(−109≤ti,j≤109-10^9 \leq t_{i,j} \leq 10^9)。

输出格式

Print one integer, denoting the maximum possible number of cell-disjoint nice rectangles.

输出一个整数,表示互不相交(即无公共单元格)的“好”矩形的最大可能数量。

输入输出样例

  • 输入#1

    6
    70 70 70 70 70 -15
    90 -60 -30 30 -30 15

    输出#1

    3
  • 输入#2

    4
    0 -1 0 0
    0 0 1 0

    输出#2

    6
  • 输入#3

    3
    1000000000 999999999 -1000000000
    999999999 -1000000000 -999999998

    输出#3

    1

说明/提示

In the first sample, there are four nice rectangles:

Limak can't choose all of them because they are not disjoint. He should take three nice rectangles: those denoted as blue frames on the drawings.

In the second sample, it's optimal to choose six nice rectangles, each consisting of one cell with a number 0.

In the third sample, the only nice rectangle is the whole grid — the sum of all numbers is 0. Clearly, Limak can choose at most one nice rectangle, so the answer is 1.

在第一个样例中,共有四个“好矩形”:

Limak 无法选择全部这四个矩形,因为它们彼此不互不相交(即存在重叠)。他应选择其中三个“好矩形”,即图中用蓝色边框标出的那三个。

在第二个样例中,最优方案是选择六个“好矩形”,每个矩形仅包含一个数字为 0 的单元格。

在第三个样例中,唯一的“好矩形”是整个网格——所有数字之和为 0。显然,Limak 最多只能选择一个“好矩形”,因此答案为 1。

输入解题思路,AI测评打分。不知道怎么写?

首页