Hello 2020 B. New Year and Ascent Sequence

Posted c4lnn

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Hello 2020 B. New Year and Ascent Sequence相关的知识,希望对你有一定的参考价值。

题目:https://codeforces.com/contest/1284/problem/B
思路:定义一个长度为 (l) 的序列中 (a) 存在 (a_i<a_j(1le ile jle l))(Ascent;Sequence)
对于序列 (p) 和序列 (q),若 (p+q)(Ascent;Sequence) 则为有效组合
(n) 个序列中有多少种有效组合
(p+q) 为无效组合只有一种情况:(p)(q) 本身都不是 (Ascent;Sequence)(p_{min}>q_{max})
因此对于每个序列只要找出有多少本身不是 (Ascent;Sequence) 的序列的最大值 (le) 该序列最小值的个数
最后答案为 (n^2-)无效组合数

#include<bits/stdc++.h>
 
using namespace std;
  
typedef long long ll;
 
typedef vector<int> vi;
 
const int N=1e5+5;
 
int n;
struct node
{
    int minn=INT_MAX;
    int maxn=-1;
}state[N];
int vis[N];
int cnt_max[N*10];
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    //freopen("in.txt","r",stdin);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int l;
        cin>>l;
        for(int j=0;j<l;j++)
        {
            int t;
            cin>>t;
            if(vis[i]==0)
            {
                if(t>state[i].minn) vis[i]=1;
                state[i].maxn=max(state[i].maxn,t);
                state[i].minn=min(state[i].minn,t);
            }
            
        }
        if(vis[i]==0) cnt_max[state[i].maxn]++;
    }
    for(int i=1;i<=1000000;i++) cnt_max[i]+=cnt_max[i-1];
    ll ans=(ll)n*n;
    for(int i=0;i<n;i++) if(vis[i]==0) ans-=cnt_max[state[i].minn];
    cout<<ans<<endl;
    return 0;
}

以上是关于Hello 2020 B. New Year and Ascent Sequence的主要内容,如果未能解决你的问题,请参考以下文章

CF Hello2020 D. New Year and Conference

CF Hello 2020 E.New Year and Castle Construction

B. Lunar New Year and Food Ordering

Codeforces Good Bye 2017 B. New Year and Buggy Bot 枚举全排列模拟

Good Bye 2015 B. New Year and Old Property

Codeforces Round #536 (Div. 2) B. Lunar New Year and Food Ordering