Submission #900968

#TimeUsernameProblemLanguageResultExecution timeMemory
9009688pete8Zoltan (COCI16_zoltan)C++17
98 / 140
236 ms34036 KiB
#include<iostream> #include<stack> #include<map> #include<vector> #include<string> #include<unordered_map> #include <queue> #include<cstring> #include<float.h> #include<limits.h> #include <cassert> #include<cmath> #include<set> #include<algorithm> #include <iomanip> #include<numeric> //gcd(a,b) #include<bitset> using namespace std; #define ll long long #define f first #define endl "\n" #define s second #define pii pair<int,int> #define ppii pair<int,pii> #define vi vector<int> #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define F(n) for(int i=0;i<n;i++) #define lb lower_bound #define ub upper_bound using namespace std; #define int long long #define double long double #define fastio ios::sync_with_stdio(false);cin.tie(NULL); #pragma GCC optimize ("03,unroll-loops") const int mod=1e9+7,mxn=2e5,lg=22,inf=1e18,minf=-1e18,Mxn=100000; int val[mxn+10],n,p[mxn+10]; pii merg(pii a,pii b){ if(a.f!=b.f||a.f==0||b.f==0)return max(a,b); else return {a.f,(b.s+a.s)%mod}; } struct seg{ pii seg[4*mxn+10]; void update(int l,int r,int node,int pos,pii val){ if(l==r){ seg[node]=merg(seg[node],val); return ; } int mid=l+(r-l)/2; if(pos<=mid)update(l,mid,node<<1,pos,val); else update(mid+1,r,(node<<1)^1,pos,val); seg[node]=merg(seg[node<<1],seg[(node<<1)^1]); } pii qry(int l,int r,int node,int ql,int qr){ if(l>qr||r<ql)return {0,0}; if(l>=ql&&r<=qr)return seg[node]; int mid=l+(r-l)/2; return merg(qry(l,mid,node<<1,ql,qr),qry(mid+1,r,(node<<1)^1,ql,qr)); } void init(){for(int i=0;i<=4*n;i++)seg[i]={0,1};} }t[2]; pii dp[mxn+10][2]; int32_t main(){ fastio cin>>n; vector<int>v(n); for(int i=0;i<n;i++)cin>>v[i],val[i]=v[i]; p[0]=1; for(int i=1;i<=n;i++)p[i]=(p[i-1]*2)%mod; sort(all(v)); for(int i=0;i<n;i++)val[i]=lb(all(v),val[i])-v.begin()+1; pii l,r; t[0].init(); t[1].init(); pii ans={0,0}; for(int i=n-1;i>=0;i--){ pii cur=t[0].qry(0,n+1,1,0,val[i]-1),cur2=t[1].qry(0,n+1,1,val[i]+1,n+1); cur.f++; cur2.f++; ans=merg(ans,{cur.f+cur2.f-1,(cur.s*cur2.s)%mod}); t[0].update(0,n+1,1,val[i],cur); t[1].update(0,n+1,1,val[i],cur2); } ans.s=((p[n-ans.f]*ans.s)%mod); cout<<ans.f<<" "<<ans.s; }
#Verdict Execution timeMemoryGrader output
Fetching results...