Distinct Rows in Submatrices

All submissions for this problem are available.
###Read problems statements [Hindi](http://www.codechef.com/download/translated/OCT18/hindi/DISTRING.pdf) ,[Bengali](http://www.codechef.com/download/translated/OCT18/bengali/DISTRING.pdf) , [Mandarin chinese](http://www.codechef.com/download/translated/OCT18/mandarin/DISTRING.pdf) , [Russian](http://www.codechef.com/download/translated/OCT18/russian/DISTRING.pdf) and [Vietnamese](http://www.codechef.com/download/translated/OCT18/vietnamese/DISTRING.pdf) as well. Let's define the *strength* of a matrix as the number of distinct rows in it. Two rows $a_1, a_2, \dots, a_n$ and $b_1, b_2, \dots, b_n$ are distinct if there is an index $i$ such that $a_i \neq b_i$. You are given an integer matrix $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). A submatrix of $A$ is formed as the intersection of rows $r_1$ through $r_2$ and columns $c_1$ through $c_2$ for any $r_1 \le r_2, c_1 \le c_2$. Find the sum of the strengths of all submatrices of $A$. ### Input  The first line of the input contains two spaceseparated integers $N$ and $M$.  $N$ lines follow. For each $i$ ($1 \le i \le N$), the $i$th of these lines contains $M$ spaceseparated integers $A_{i, 1}, A_{i, 2}, \dots, A_{i, M}$. ### Output Print a single line containing one integer — the sum of strengths of all the submatrices. ### Constraints  $1 \le N \cdot M \le 500,000$  $ 1 \le A_{i,j} \le 10^9$ for each valid $i, j$ ### Subtasks **Subtask #1 (20 points):** $1 \le N \cdot M \le 1,000$ **Subtask #2 (80 points):** original constraints ### Example Input ``` 2 2 1 1 1 2 ``` ### Example Output ``` 11 ``` ### Explanation The submatrices are ``` 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 ``` with strengths $1, 1, 1, 1, 1, 1, 1, 2, 2$ respectively. The sum of these strengths is $11$.Author:  jtnydv25 
Editorial  https://discuss.codechef.com/problems/DISTRING 
Tags  dsu, hard, jtnydv25, lcp, oct18, suffixarray 
Date Added:  24092018 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions