CF811E.Vladik and Entertaining Flags

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

In his spare time Vladik estimates beauty of the flags.

Every flag could be represented as the matrix n×mn×m which consists of positive integers.

Let's define the beauty of the flag as number of components in its matrix. We call component a set of cells with same numbers and between any pair of cells from that set there exists a path through adjacent cells from same component. Here is the example of the partitioning some flag matrix into components:

But this time he decided to change something in the process. Now he wants to estimate not the entire flag, but some segment. Segment of flag can be described as a submatrix of the flag matrix with opposite corners at (1,l)(1,l) and (n,r)(n,r) , where conditions 1<=l<=r<=m1<=l<=r<=m are satisfied.

Help Vladik to calculate the beauty for some segments of the given flag.

输入格式

First line contains three space-separated integers nn , mm , qq ( 1<=n<=101<=n<=10 , 1<=m,q<=1051<=m,q<=10^{5} ) — dimensions of flag matrix and number of segments respectively.

Each of next nn lines contains mm space-separated integers — description of flag matrix. All elements of flag matrix is positive integers not exceeding 10610^{6} .

Each of next qq lines contains two space-separated integers ll , rr ( 1<=l<=r<=m1<=l<=r<=m ) — borders of segment which beauty Vladik wants to know.

输出格式

For each segment print the result on the corresponding line.

输入输出样例

  • 输入#1

    4 5 4
    1 1 1 1 1
    1 2 2 3 3
    1 1 1 2 5
    4 4 5 5 5
    1 5
    2 5
    1 2
    4 5
    

    输出#1

    6
    7
    3
    4
    

说明/提示

Partitioning on components for every segment from first test case:

首页