【链接】 我是链接,点我呀:)

【题意】

相当于问你这m个数组的任意长度公共子串的个数

【题解】

枚举第1个数组以i为起点的子串。
假设i..j是以i开头的子串能匹配的最长的长度。
(这个j可以给2..m这些数组用一个类似链表的东西很快得到,O((j-i+1)*M)的复杂度即可完成。
那么我们会发现,我们不需要重新再从i+1开始枚举。
因为i..j这一段的任意一个子串都是满足要求(公共子串)的。
而它有len*(1+len)/2个子串
那么我们从j+1开始继续上述步骤就Ok了。
注意m=1的时候。。别死循环了。。。j加一个上界n哦.

【代码】

#include <bits/stdc++.h>
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--) using namespace std; const int N = 1e5;
const int M = 10; int a[M+2][N+10];
int n,m; int main()
{
scanf("%d%d",&n,&m);
rep1(i,1,n) scanf("%d",&a[1][i]);
for (int i = 2;i <= m;i++){
rep1(j,1,n)
{
int x;
scanf("%d",&x);
a[i][x] = j;
}
}
int last = 0;
long long ans = 0;
for (int i = 1;i <= n;i++){
int k = i;
while (1){
int ok = 1;
rep1(j,2,m)
if (k+1<=n && a[j][a[1][k]]+1==a[j][a[1][k+1]])
ok++;
if (ok==m && k+1<=n){
k++;
}else break;
}
ans = ans + 1LL*(1+k-i+1)*(k-i+1)/2;
i = k;
}
printf("%lld\n",ans);
return 0;
}

【Codeforces Round #519 by Botan Investments D】Mysterious Crime的更多相关文章

  1. 【Codeforces Round #519 by Botan Investments E】Train Hard, Win Easy

    [链接] 我是链接,点我呀:) [题意] [题解] 设每个人做第一题.第二题的分数分别为x,y 我们先假设没有仇视关系. 即每两个人都能进行一次训练. 那么 对于第i个人. 考虑第j个人对它的贡献 如 ...

  2. 【Codeforces Round #519 by Botan Investments A】 Elections

    [链接] 我是链接,点我呀:) [题意] [题解] 枚举k 那么另外一个人的得票就是nk-sum(ai) 找到最小的满足nk-sum(ai)>sum(ai)的k就ok了 [代码] #includ ...

  3. 【 Codeforces Round #519 by Botan Investments B】Lost Array

    [链接] 我是链接,点我呀:) [题意] [题解] 枚举k 不难根据a得到x[0..k-1] 然后再根据a[k+1..n]来验证一下得到的x是否正确就好. [代码] #include <bits ...

  4. 【Codeforces Round #519 by Botan Investments C】 Smallest Word

    [链接] 我是链接,点我呀:) [题意] [题解] 模拟了一两下.. 然后发现. 对于每一个前缀. 组成的新的最小字典序的字符串 要么是s[i]+reverse(前i-1个字符经过操作形成的最大字典序 ...

  5. Codeforces Round #519 by Botan Investments

    Codeforces Round #519 by Botan Investments #include<bits/stdc++.h> #include<iostream> #i ...

  6. Codeforces Round #519 by Botan Investments(前五题题解)

    开个新号打打codeforces(以前那号玩废了),结果就遇到了这么难一套.touristD题用了map,被卡掉了(其实是对cf的评测机过分自信),G题没过, 700多行代码,码力惊人.关键是这次to ...

  7. Codeforces Round #519 by Botan Investments F. Make It One

    https://codeforces.com/contest/1043/problem/F 题意 给你n个数,求一个最小集合,这个集合里面数的最大公因数等于1 1<=n<=3e5 1< ...

  8. Codeforces Round #519 by Botan Investments翻车记

    A:枚举答案即可.注意答案最大可达201,因为这个wa了一发瞬间爆炸. #include<iostream> #include<cstdio> #include<cmat ...

  9. 【Codeforces Round #519】

    A:https://www.cnblogs.com/myx12345/p/9872082.html B:https://www.cnblogs.com/myx12345/p/9872124.html ...

随机推荐

  1. USACO money packageDP

    裸0/1背包,就是从各种币种里面拿来凑足N元,求最多有多种方案.用dp[i][j]表示选前i个币种凑成j的方案数量 状态转移方程: dp[i][j] = dp[i- 1][j]    j < c ...

  2. sharepoint类型转换

    sharepoint学习汇总 http://blog.csdn.net/qq873113580/article/details/20390149 r[col.ColumnName] = GetType ...

  3. Codeforces--626B--Cards(模拟)

     Cards Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Sta ...

  4. hdoj Radar Installation

    Problem Description Assume the coasting is an infinite straight line. Land is in one side of coastin ...

  5. bzoj 1191 [ HNOI 2006 ] 超级英雄Hero —— 二分图匹配

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1191 就是二分图匹配的裸题: 注意题目要求是第一次匹配失败就退出!没仔细看题差点丢失1A. ...

  6. C语言实现字符串拼接

    #include <stdio.h>#include <stdlib.h>#include <string.h> char* str_contact(const c ...

  7. A Reusable Aspect for Memory Profiling

    例子: malPro.acc文件: #include <stdlib.h> size_t totalMemoryAllocated; int totalAllocationFuncCall ...

  8. hdu 3037Saving Beans(卢卡斯定理)

    Saving Beans Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  9. JVM内存模型和GC垃圾回收

    JVM 内存区域 1.程序计数器 这是一块较小的内存空间,它的作用可以看做是当前线程所执行的字节码的行号指示器,指的是上次代码被执行的地方,线程私有. 2.Java 虚拟机栈 它是 Java方法执行的 ...

  10. 2015 多校赛 第七场 1011 (hdu 5379)

    题意:给定一棵树,树上有 n 个节点.问有多少种方案,使得在每个节点上依次放置数 1~n 后,每个节点的儿子节点上的数连续(比如 1 为根,有1-2,1-3,1-4,则令2,3,4上的数连续),每个子 ...