#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
//#define endl '\n'
llo mod=1e9+7;
llo n;
llo it[200001];
pair<llo,llo> dp[200001];
pair<llo,llo> dp2[200001];
llo pre[200001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for(llo i=0;i<n;i++){
cin>>it[i];
}
for(llo i=0;i<n/2;i++){
swap(it[i],it[n-i-1]);
}
pre[0]=1;
for(llo i=1;i<=n;i++){
pre[i]=(pre[i-1]*2)%mod;
}
if(true){
dp[0]={1,1};
vector<vector<pair<llo,llo>>> ss;
ss.pb({{it[0],1}});
for(llo i=1;i<n;i++){
int ind=-1;
if(it[i]>ss.back().back().a){
ind=ss.size()-1;
int low=0;
int high=ss[ind].size()-1;
while(low<high-1){
int mid=(low+high)/2;
if(ss[ind][mid].a<it[i]){
high=mid;
}
else{
low=mid;
}
}
int ind2=high;
if(ss[ind][low].a<it[i]){
ind2=min(ind2,low);
}
int co=ss[ind].back().b;
if(ind2>0){
co=(co-ss[ind][ind2-1].b+mod)%mod;
}
dp[i]={ss.size()+1,co};
ss.pb({{it[i],dp[i].b}});
}
else if(it[i]<=ss[0].back().a){
dp[i]={1,1};
ss[0].pb({it[i],(ss[0].back().b+dp[i].b)%mod});
}
else{
int low=0;
int high=ss.size()-2;
while(low<high-1){
int mid=(low+high)/2;
if(ss[mid].back().a<it[i]){
low=mid;
}
else{
high=mid;
}
}
int ind=low;
if(ss[high].back().a<it[i]){
ind=max(ind,high);
}
low=0;
high=ss[ind].size()-1;
while(low<high-1){
int mid=(low+high)/2;
if(ss[ind][mid].a<it[i]){
high=mid;
}
else{
low=mid;
}
}
int ind2=high;
if(ss[ind][low].a<it[i]){
ind2=min(ind2,low);
}
int co=ss[ind].back().b;
if(ind2>0){
co=(co-ss[ind][ind2-1].b+mod)%mod;
}
dp[i]={ind+2,co};
ss[ind+1].pb({it[i],(ss[ind+1].back().b+dp[i].b)%mod});
}
}
}
for(int i=0;i<n;i++){
it[i]=-it[i];
}
if(true){
dp2[0]={1,1};
vector<vector<pair<llo,llo>>> ss;
ss.pb({{it[0],1}});
for(llo i=1;i<n;i++){
int ind=-1;
if(it[i]>ss.back().back().a){
ind=ss.size()-1;
int low=0;
int high=ss[ind].size()-1;
while(low<high-1){
int mid=(low+high)/2;
if(ss[ind][mid].a<it[i]){
high=mid;
}
else{
low=mid;
}
}
int ind2=high;
if(ss[ind][low].a<it[i]){
ind2=min(ind2,low);
}
int co=ss[ind].back().b;
if(ind2>0){
co=(co-ss[ind][ind2-1].b+mod)%mod;
}
dp2[i]={ss.size()+1,co};
ss.pb({{it[i],dp2[i].b}});
}
else if(it[i]<=ss[0].back().a){
dp2[i]={1,1};
ss[0].pb({it[i],(ss[0].back().b+dp2[i].b)%mod});
}
else{
int low=0;
int high=ss.size()-2;
while(low<high-1){
int mid=(low+high)/2;
if(ss[mid].back().a<it[i]){
low=mid;
}
else{
high=mid;
}
}
int ind=low;
if(ss[high].back().a<it[i]){
ind=max(ind,high);
}
low=0;
high=ss[ind].size()-1;
while(low<high-1){
int mid=(low+high)/2;
if(ss[ind][mid].a<it[i]){
high=mid;
}
else{
low=mid;
}
}
int ind2=high;
if(ss[ind][low].a<it[i]){
ind2=min(ind2,low);
}
int co=ss[ind].back().b;
if(ind2>0){
co=(co-ss[ind][ind2-1].b+mod)%mod;
}
dp2[i]={ind+2,co};
ss[ind+1].pb({it[i],(ss[ind+1].back().b+dp2[i].b)%mod});
}
}
}
for(llo i=0;i<n/2;i++){
swap(dp[i],dp[n-i-1]);
}
for(llo i=0;i<n/2;i++){
swap(dp2[i],dp2[n-i-1]);
}
/* for(llo i=0;i<n;i++){
cout<<dp[i].a<<":"<<dp[i].b<<endl;
}
cout<<endl;
for(llo i=0;i<n;i++){
cout<<dp2[i].a<<":"<<dp2[i].b<<endl;
}
cout<<endl;*/
llo ans=0;
llo ma=0;
for(llo i=0;i<n;i++){
ma=max(ma,dp[i].a+dp2[i].a-1);
}
for(llo i=0;i<n;i++){
if(dp[i].a+dp2[i].a-1==ma){
llo ans2=(dp[i].b*dp2[i].b)%mod;
ans2=(ans2*pre[n-ma])%mod;
/*if(i>0){
ans2=(ans2*2)%mod;
}*/
ans=(ans2+ans)%mod;
//cout<<ans2<<":";
}
}
cout<<ma<<" "<<ans<<endl;
/* vector<vector<pair<llo,llo>>> ss;
ss.pb({{-it[i],1}});
vector<vector<pair<llo,llo>>> tt;
tt.pb({{it[i],1}});
for(llo i=1;i<n;i++){
if(it[i]==it[0]){
continue;
}
llo xx=it[i];
else if(it[i]<it[0]){
}
else{
if(xx<=tt[0].back().a){
}
if(xx>tt[tt.size()-1].back().a){
tt
}
}
}*/
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
60 ms |
14996 KB |
Output is correct |
12 |
Correct |
53 ms |
13632 KB |
Output is correct |
13 |
Correct |
48 ms |
11512 KB |
Output is correct |
14 |
Correct |
79 ms |
10284 KB |
Output is correct |
15 |
Correct |
101 ms |
12808 KB |
Output is correct |
16 |
Correct |
119 ms |
14688 KB |
Output is correct |
17 |
Correct |
151 ms |
17340 KB |
Output is correct |
18 |
Correct |
156 ms |
17340 KB |
Output is correct |
19 |
Correct |
165 ms |
17468 KB |
Output is correct |
20 |
Correct |
152 ms |
17340 KB |
Output is correct |