D. Mysterious Crime

题解:因为是Codeforces Round #519 by Botan Investments D_#ifndef个不同的数,所以先预处理出第一行每个数字的下一个数字是什么,然后去剩下的Codeforces Round #519 by Botan Investments D_预处理_02行去寻找满足Codeforces Round #519 by Botan Investments D_子串_03,然后Codeforces Round #519 by Botan Investments D_codeforces_04,这样最后找到这第一行的Codeforces Round #519 by Botan Investments D_#ifndef个数字在Codeforces Round #519 by Botan Investments D_#ifndef_06行中出现了Codeforces Round #519 by Botan Investments D_#ifndef_06次的数,然后考虑连续子串的情况,方案数就为Codeforces Round #519 by Botan Investments D_子串_08(比如Codeforces Round #519 by Botan Investments D_子串_09都出现了Codeforces Round #519 by Botan Investments D_#ifndef_06次,可行子序列为Codeforces Round #519 by Botan Investments D_codeforces_11)。统计一下即可。

代码

#include<bits/stdc++.h>

using namespace std;
const int N = 100100;
struct node{
int nxt, cnt;
}loc[N];
int num[13][N];
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.in","r",stdin);
#endif
int n,m;
cin>>n>>m;
for(int i = 1; i <= m; ++i) {
for(int j = 1; j <= n; ++j) {
scanf("%d",&num[i][j]);
}
}
for(int i = 1; i < n; ++i) {
loc[num[1][i]].nxt = num[1][i + 1];
loc[num[1][i]].cnt = 1;
}
for(int i = 2; i <= m; ++i) {
for(int j = 1; j < n; ++j) {
if(loc[num[i][j]].nxt == num[i][j + 1]) loc[num[i][j]].cnt++;
}
}
long long sum = 1, ans = 0;
for(int i = 1; i < n; ++i) {
if(loc[num[1][i]].cnt == m) sum++;
else ans += sum * (sum + 1) / 2, sum = 1;
}
if(sum > 0) ans += sum * (sum + 1) / 2;
cout<< ans << endl;
return 0;
}