记录编号 587114 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [雅礼集训 2017 Day10] 数列 最终得分 100
用户昵称 Gravatar┭┮﹏┭┮ 是否通过 通过
代码语言 C++ 运行时间 0.830 s
提交时间 2024-03-14 19:26:40 内存使用 9.73 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 4e5+10;
const ll inf = 1e17,mod = 1e9+7;
int n,m,b[N],a[N];
struct made{
    int mx;ll cnt;
}f[N];
struct BIT{
    int c[N];ll cnt[N];
    void clear(){memset(c,0,sizeof(c)),memset(cnt,0,sizeof cnt);}
    inline int lowbit(int x){return x & (-x);}
    void add(int x,int val,ll cn){
        for(;x <= n;x += lowbit(x)){
            if(val > c[x])c[x] = val,cnt[x] = cn % mod;
            else if(val == c[x])cnt[x] = (cnt[x] + cn) % mod;
        }
    }
    made ask(int x){
        made ans = {1,1};
        for(;x > 0;x -= lowbit(x)){
            if(c[x] + 1 > ans.mx)ans = {c[x]+1,cnt[x]%mod};
            else if(c[x] + 1 == ans.mx)ans.cnt = (ans.cnt + cnt[x]) % mod;
        }
        return ans;
    }
}t;
int ans;
ll s;
ll po(ll x,ll y){
    if(y == -1)y = (mod-2);
    ll ans = 1;
    while(y){
        if(y & 1)ans = (ans * x) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }return ans;
}
int main(){
	freopen("lisshulie.in","r",stdin);
    freopen("lisshulie.out","w",stdout);
    scanf("%d",&n);
    for(int i = 1;i <= n;i++)scanf("%d",&a[i+n]),b[i] = a[i+n];
    sort(b+1,b+1+n);
    m = unique(b+1,b+1+n) - (b+1);
    for(int i = 1;i <= n;i++)a[i+n] = lower_bound(b+1,b+1+m,a[i+n]) - b;
    for(int i = 1;i <= n;i++)a[i] = a[2*n-i+1];
    t.clear();
    for(int i = 1;i <= 2*n;i++){
        f[i] = t.ask(a[i]-1);
        t.add(a[i],f[i].mx,f[i].cnt);
        ans = max(ans,f[i].mx);
    }
    for(int i = 1;i <= 2*n;i++)
        if(f[i].mx == ans)s = (s + f[i].cnt) % mod;
    printf("%d %lld\n",ans,s*po(2,n-ans-1)%mod);
    

	return 0;

}