B. New Year and Ascent Sequence:题目
小小思维题
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> a((int)6e5);
vector<int> b((int)6e5), c((int)6e5);
const int mod = 1e9 + 7;
signed main()
{
int t;
cin>>t;
int cnt = 0;
a[0] = 0x3f3f3f3f;
while (t--)
{
int n;
cin>>n;
int ff = 0;
for (int i=1;i<=n;i++)
{
cin>>a[i];
if (a[i]>a[i-1]) ff = 1;
}
if (ff) c[cnt] = 0x3f3f3f3f,b[cnt] = -1;
else c[cnt] = a[1],b[cnt] = a[n];
cnt++;
}
sort(c.begin(),c.begin()+cnt);
int res = 0;
for (int i=0;i<cnt;i++)
{
int k = lower_bound(c.begin(),c.begin()+cnt,b[i]+1)-c.begin();
res+=cnt-k;
}
cout<<res<<endl;
}