CF1928F.Digital Patterns
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Anya is engaged in needlework. Today she decided to knit a scarf from semi-transparent threads. Each thread is characterized by a single integer — the transparency coefficient.
The scarf is made according to the following scheme: horizontal threads with transparency coefficients a1,a2,…,an and vertical threads with transparency coefficients b1,b2,…,bm are selected. Then they are interwoven as shown in the picture below, forming a piece of fabric of size n×m , consisting of exactly nm nodes:
Example of a piece of fabric for n=m=4 .After the interweaving tightens and there are no gaps between the threads, each node formed by a horizontal thread with number i and a vertical thread with number j will turn into a cell, which we will denote as (i,j) . Cell (i,j) will have a transparency coefficient of ai+bj .
The interestingness of the resulting scarf will be the number of its sub-squares † in which there are no pairs of neighboring †† cells with the same transparency coefficients.
Anya has not yet decided which threads to use for the scarf, so you will also be given q queries to increase/decrease the coefficients for the threads on some ranges. After each query of which you need to output the interestingness of the resulting scarf.
† A sub-square of a piece of fabric is defined as the set of all its cells (i,j) , such that x0≤i≤x0+d and y0≤j≤y0+d for some integers x0 , y0 , and d ( 1≤x0≤n−d , 1≤y0≤m−d , d≥0 ).
†† . Cells (i1,j1) and (i2,j2) are neighboring if and only if ∣i1−i2∣+∣j1−j2∣=1 .
输入格式
The first line contains three integers n , m , and q ( 1≤n,m≤3⋅105 , 0≤q≤3⋅105 ) — the number of horizontal threads, the number of vertical threads, and the number of change requests.
The second line contains n integers a1,a2,…,an ( −109≤ai≤109 ) — the transparency coefficients for the horizontal threads, with the threads numbered from top to bottom.
The third line contains m integers b1,b2,…,bm ( −109≤bi≤109 ) — the transparency coefficients for the vertical threads, with the threads numbered from left to right.
The next q lines specify the change requests. Each request is described by a quadruple of integers t , l , r , and x ( 1≤t≤2 , l≤r , −109≤x≤109 ). Depending on the parameter t in the request, the following actions are required:
- t=1 . The transparency coefficients for the horizontal threads in the range [l,r] are increased by x (in other words, for all integers l≤i≤r , the value of ai is increased by x );
- t=2 . The transparency coefficients for the vertical threads in the range [l,r] are increased by x (in other words, for all integers l≤i≤r , the value of bi is increased by x ).
输出格式
Output (q+1) lines. In the (i+1) -th line ( 0≤i≤q ), output a single integer — the interestingness of the scarf after applying the first i requests.
输入输出样例
输入#1
4 4 0 1 1 2 3 1 2 2 3
输出#1
20
输入#2
3 3 2 1 1 1 2 2 8 1 2 3 1 2 2 3 -6
输出#2
9 10 11
输入#3
3 2 2 -1000000000 0 1000000000 -1000000000 1000000000 1 1 1 1000000000 2 2 2 -1000000000
输出#3
8 7 7
说明/提示
In the first example, the transparency coefficients of the cells in the resulting plate are as follows:
2334233434454556Then there are the following sub-squares that do not contain two neighboring cells with the same transparency coefficient:
- Each of the 16 cells separately;
- A sub-square with the upper left corner at cell (3,1) and the lower right corner at cell (4,2) ;
- A sub-square with the upper left corner at cell (2,3) and the lower right corner at cell (3,4) ;
- A sub-square with the upper left corner at cell (2,1) and the lower right corner at cell (3,2) ;
- A sub-square with the upper left corner at cell (3,3) and the lower right corner at cell (4,4) .
In the second example, after the first query, the transparency coefficients of the horizontal threads are [1,2,2] . After the second query, the transparency coefficients of the vertical threads are [2,−4,2] .