# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
445506 | keta_tsimakuridze | Zoltan (COCI16_zoltan) | C++14 | 564 ms | 23336 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define f first
#define s second
#define pii pair<int,int>
using namespace std;
const int N=2e5+5,mod=1e9+7;
int t,a[N],b[N],n,pwr[N];
pair<int,int> tree[4*N][2],l[N][2];
map<int,int> ind;
void upd(pii &a,pii b){
if(a.f == b.f) {
a.s = (a.s + b.s)%mod;
}
else if(a.f < b.f) {
a.s = b.s;
a.f = b.f;
}
}
void update(int u,int ind,int l,int r,int val1,int val2,int t) {
if(l>ind || r<ind) return;
if(l==r) {
upd(tree[u][t],{val1,val2});
return;
}
int mid = (l+r)/2;
update(2*u,ind,l,mid,val1,val2,t);
update(2*u+1,ind,mid+1,r,val1,val2,t);
tree[u][t] = {0,0};
upd(tree[u][t],tree[2*u][t]);
upd(tree[u][t],tree[2*u+1][t]);
}
pii getans(int u,int start,int end,int l,int r,int t) {
if(l > end || r<start) return {0,0};
if(start<=l && r<=end) return tree[u][t];
int mid = (l+r)/2;
pii g1 = getans(2*u,start,end,l,mid,t);
pii g2 = getans(2*u+1,start,end,mid+1,r,t);
upd(g1,g2);
return g1;
}
main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
b[i] = a[i];
}
sort(b+1,b+n+1);
int idx = 0;
b[0] = -1;
pwr[0] = 1;
for(int i=1;i<=n;i++){
pwr[i] = pwr[i-1] * 2 % mod;
if(b[i]!=b[i-1]) idx++;
ind[b[i]] = idx;
}
for(int i=n;i>=2;i--){
a[i] = ind[a[i]];
pii p = getans(1,1,a[i]-1,1,n,1);
p.f++;
if(p.f == 1) p.s = 1;
upd(l[a[i]][1],p);
update(1,a[i],1,n,p.f,p.s,1);
p = getans(1,a[i]+1,n,1,n,0);
p.f++;
if(p.f == 1) p.s = 1;
update(1,a[i],1,n,p.f,p.s,0);
upd(l[a[i]][0],p);
}
l[0][1] = {0,1};
l[idx+1][0] = {0,1};
pii ans;
ans = {0,0};
for(int i=idx;i>=0;i--){
upd(l[i][0],l[i+1][0]);
}
for(int i=0;i<=idx;i++) {
if(i)upd(l[i][1],l[i-1][1]);
upd(ans,{l[i][1].f + l[i+1][0].f,(long long) l[i][1].s * l[i+1][0].s %mod* pwr[n -l[i][1].f - l[i+1][0].f - 1]%mod});
}
//
a[1] = ind[a[1]];
pii p = getans(1,a[1]+1,n,1,n,0);
p.f++;
if(p.f==1) p.s = 1;
for(int i=0; i<a[1]; i++) {
upd(ans,{l[i][1].f + p.f,(long long) l[i][1].s * p.s %mod* pwr[n -l[i][1].f - p.f]%mod});
}
cout<<ans.f<<" "<<ans.s;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |