CF1043D.Mysterious Crime

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Acingel is a small town. There was only one doctor here — Miss Ada. She was very friendly and nobody has ever said something bad about her, so who could've expected that Ada will be found dead in her house? Mr Gawry, world-famous detective, is appointed to find the criminal. He asked mm neighbours of Ada about clients who have visited her in that unlucky day. Let's number the clients from 11 to nn. Each neighbour's testimony is a permutation of these numbers, which describes the order in which clients have been seen by the asked neighbour.

However, some facts are very suspicious – how it is that, according to some of given permutations, some client has been seen in the morning, while in others he has been seen in the evening? "In the morning some of neighbours must have been sleeping!" — thinks Gawry — "and in the evening there's been too dark to see somebody's face...". Now he wants to delete some prefix and some suffix (both prefix and suffix can be empty) in each permutation, so that they'll be non-empty and equal to each other after that — some of the potential criminals may disappear, but the testimony won't stand in contradiction to each other.

In how many ways he can do it? Two ways are called different if the remaining common part is different.

阿辛格尔是一个小镇。这里只有一位医生——艾达小姐。她为人非常友善,从未有人说过她的坏话,因此谁又能料到艾达竟会被人发现死在自己家中?享誉世界的著名侦探加里先生被委派来侦破此案。他向艾达的 mm 位邻居询问了那个不幸日子里曾拜访过艾达的客户情况。我们把客户编号为 11 到 nn。每位邻居的证词都是这些编号的一个排列,描述了该邻居所见到的客户顺序。

然而,某些事实十分可疑——根据给出的部分排列,某位客户似乎是在上午被看到的,而根据另一些排列,他却是在傍晚被看到的!“上午时,有些邻居一定正在睡觉!”加里心想,“而傍晚时又太黑,根本看不清人的脸……”现在,他希望从每个排列中各自删去某个前缀和某个后缀(前缀与后缀均可为空),使得删除后所有排列均非空,且彼此完全相同——部分潜在嫌疑人可能因此被排除,但所有证词之间将不再相互矛盾。

他有多少种不同的操作方式?若两种方式所得到的公共剩余部分不同,则称这两种方式不同。

输入格式

The first line contains two integers nn and mm (1≤n≤100 0001 \le n \le 100\,000, 1≤m≤101 \le m \le 10) — the number of suspects and the number of asked neighbors.

Each of the next mm lines contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤n1 \le a_i \le n). It is guaranteed that these integers form a correct permutation (that is, each number from 11 to nn appears exactly once).

第一行包含两个整数 nn 和 mm(1≤n≤100 0001 \le n \le 100\,000,1≤m≤101 \le m \le 10)—— 分别表示嫌疑人的数量和被询问的邻居数量。

接下来的 mm 行中,每行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤n1 \le a_i \le n)。保证这些整数构成一个合法的排列(即从 11 到 nn 的每个数恰好出现一次)。

输出格式

Output a single integer denoting the number of ways to delete some prefix and some suffix of each permutation (possibly empty), such that the remaining parts will be equal and non-empty.

输出一个整数,表示对每个排列删除某个前缀和某个后缀(可以为空)的方式数目,使得剩余部分相等且非空。

输入输出样例

  • 输入#1

    3 2
    1 2 3
    2 3 1

    输出#1

    4
  • 输入#2

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

    输出#2

    5
  • 输入#3

    2 2
    1 2
    2 1

    输出#3

    2

说明/提示

In the first example, all possible common parts are [1][1], [2][2], [3][3] and [2,3][2, 3].

In the second and third examples, you can only leave common parts of length 11.

在第一个例子中,所有可能的公共子数组为 [1][1]、[2][2]、[3][3] 和 [2,3][2, 3]。

在第二个和第三个例子中,你只能保留长度为 11 的公共子数组。

输入解题思路,AI测评打分。不知道怎么写?

首页