304011: CF771E. Bear and Rectangle Strips
Memory Limit:256 MB
Time Limit:3 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Bear and Rectangle Strips
题意翻译
给定 $2\times n$ 的矩阵 $t$,求最多能切分出多少个和为 $0$ 的连续子矩阵。 $n\le 3\cdot 10^5$,$|t_{i,j}|\le 10^9$。题目描述
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?输入输出格式
输入格式
The first line of the input contains an integer $ n $ ( $ 1<=n<=300000 $ ) — 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} $ ( $ -10^{9}<=t_{i,j}<=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