| 记录编号 | 
        388155 | 
        评测结果 | 
        AAAAAAAAAA | 
    
    
        | 题目名称 | 
        2639.[HZOI 2015] 偏序++ | 
        最终得分 | 
        100 | 
            
    
    
        | 用户昵称 | 
         哒哒哒哒哒! | 
        是否通过 | 
        通过 | 
    
    
        | 代码语言 | 
        C++ | 
        运行时间 | 
        4.192 s  | 
    
    
        | 提交时间 | 
        2017-03-28 18:34:38 | 
        内存使用 | 
        9.32 MiB  | 
        
    
    
    
    		显示代码纯文本
		
		#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <bitset>
#include <algorithm>
using namespace std;
#define ll long long 
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
	return x*f;
}
#define bit bitset<40001>
const int maxn=40005;
int n,k,size,block[maxn];
struct Bitset{
	int a[maxn],lis[maxn];
	bit B[201];
	bit get(int p){
		p=a[p];
		int bp=block[p];
		bit ans=B[bp-1];
		for(int i=(bp-1)*size+1;i<p;i++)
			ans.set(lis[i]);
		return ans;
	}
}d[7];
void build(int op){
	for(int i=1;i<=n;i++)
		d[op].lis[d[op].a[i]]=i;
	bit t;t.reset();
	for(int i=1;i<=n;i++){
		t.set(d[op].lis[i]);
		if(i%size==0) d[op].B[i/size]=t;
	}
}
int main(){
	freopen("partial_order_plus.in","r",stdin);
	freopen("partial_order_plus.out","w",stdout);
	n=read(),k=read(),size=sqrt(n);
	
	for(int i=1;i<=n;i++) block[i]=(i-1)/size+1;
	for(int i=1;i<=n;i++) d[0].a[i]=i;
	for(int i=1;i<=k;i++)
		for(int j=1;j<=n;j++) d[i].a[j]=read();
	for(int i=0;i<=k;i++) build(i);
	int ans=0;
	for(int i=1;i<=n;i++){
		bit t=d[0].get(i);
		for(int j=1;j<=k;j++)t&=d[j].get(i);
		ans+=t.count();
	}
	printf("%d\n",ans);
	fclose(stdin);fclose(stdout);
	return 0;
}