CodeForces 1109F. Sasha and Algorithm of Silence's Sounds

Posted tinywong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces 1109F. Sasha and Algorithm of Silence's Sounds相关的知识,希望对你有一定的参考价值。

题目简述:给定一个$n imes m$的二维矩阵$a[i][j]$,其中$1 leq nm leq 2 imes 10^5$,矩阵元素$1 leq a[i][j] leq nm$且互不相等。一个区间$[l, r]$是【好】的,如果所有在$[l, r]$范围内的元素(在平面上)构成了一棵树。求【好】区间$[l, r](1 leq l leq r leq nm)$的个数。

解:code

建模:

令$G = (V, E)$表示二维矩阵$a[i][j]$对应的无向图,构造如下:

  1. $ V = { 1, 2, dots, nm }, $

  2. $ E = { (a[x_1][y_1], a[x_2][y_2]): (x1,y1)-(x2,y2) in { (0, 1), (0, -1), (-1, 0), (1, 0) } }. $

令$G_{l, r} = (V_{l, r}, E_{l, r})$表示$G$中包含节点$[l, r]$的子图,形式上,

  1. $V_{l, r} = V cap [l, r], $

  2. $E_{l, r} = E cap [l, r]^2. $

一个区间$[l, r]$是【好】的,如果$G_{l, r}$是一棵树。

对每个$1 leq r leq nm$,令$l_r$表示最小的$l$,使得$G_{l, r}$是无环图。则显然有$l_r leq l_{r+1}$。

以上是关于CodeForces 1109F. Sasha and Algorithm of Silence's Sounds的主要内容,如果未能解决你的问题,请参考以下文章

CF1109D Sasha and Interesting Fact from Graph Theory 组合数

Codeforces 1113A. Sasha and His Trip 题解

Codeforces Round #425 (Div. 2) Problem A Sasha and Sticks

CF1109B Sasha and One More Name

CodeForces 931F Teodor is not a liar!

Codeforces Round #539 (Div. 2) C Sasha and a Bit of Relax