题意:一个数字序列 S 中如果存在\(S_{i}<S_{j} (i<j)\),就说它有“ ascent ” 。在N组数字序列中两两匹配,看有多少组序列组合存在“ ascent ” 。
分析:
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MA=1e6+15;
const int MB=1e5+5;
const int INF=1e9+7;
ll n,l;
ll minn[MB],maxx[MB]; //记录每个序列最小值,最大值
ll dmax[MA]; //
ll ans=0,ax;
int flag[MB]; //自身是否满足
int main()
{
scanf("%lld",&n);
for(int i=1;i<=n;++i){
scanf("%lld",&l);
minn[i]=INF;
maxx[i]=0;
for(int j=1;j<=l;++j){
scanf("%lld",&ax);
if(ax>minn[i])flag[i]=1;
minn[i]=min(minn[i],ax);
maxx[i]=max(maxx[i],ax);
}
minn[i]=minn[i]+1; //调整最值区间
maxx[i]=maxx[i]+1;
if(flag[i]){ //如果序列本身满足条件,修改最值
minn[i]=0;
maxx[i]=1e6+5;
}
dmax[maxx[i]]++;
}
ll val1=0,val2=0;
for(int i=1e6+10;i>=0;--i){
val2=dmax[i];
dmax[i]=val1;
val1+=val2;
}
for(int i=1;i<=n;++i){
ans+=dmax[minn[i]];
}
printf("%lld\n",ans);
return 0;
}
原文:https://www.cnblogs.com/A-sc/p/12159631.html