Submission #459193

#TimeUsernameProblemLanguageResultExecution timeMemory
459193nikolapesic2802Zoltan (COCI16_zoltan)C++14
91 / 140
405 ms15736 KiB
#include<bits/stdc++.h> #define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define dec(x, y) fixed << setprecision((y)) << (x) #define xx first #define yy second #define srt(v) sort((v).begin(), (v).end()) #define srtr(v) sort((v).rbegin(), (v).rend()) #define pb push_back #define popb pop_back #define sz(a) (int)(a).size() #define len(a) (int)(a).length() #define mp make_pair using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll mod=(ll)1e9+7LL; int n, a[200010]; pii b[200010], lis[200010], lds[200010]; pair<int, ll> st[800010]; void build(int node, int tl, int tr) { if(tl==tr) {st[node].xx=0; st[node].yy=1LL; return;} int mid=(tl+tr)/2; build(2*node, tl, mid); build(2*node+1, mid+1, tr); st[node].xx=0; st[node].yy=0LL; } void upd(int node, int tl, int tr, int poz, pii val) { if(tl==tr) { if(st[node].xx!=val.xx) {st[node].xx=val.xx; st[node].yy=(ll)val.yy; return;} else {++st[node].yy; return;} } int mid=(tl+tr)/2; if(poz<=mid) upd(2*node, tl, mid, poz, val); else upd(2*node+1, mid+1, tr, poz, val); st[node].xx=max(st[2*node].xx, st[2*node+1].xx); st[node].yy=((st[2*node].xx==st[node].xx?st[2*node].yy:0LL)+(st[2*node+1].xx==st[node].xx?st[2*node+1].yy:0LL))%mod; } pair<int, ll> query(int node, int tl, int tr, int gl, int gr) { if(tl>=gl && tr<=gr) return st[node]; int mid=(tl+tr)/2; pair<int, ll> res1={0, 0}, res2={0, 0}; if(mid>=gl) res1=query(2*node, tl, mid, gl, gr); if(mid+1<=gr) res2=query(2*node+1, mid+1, tr, gl, gr); if(res1.xx>res2.xx) return res1; else if(res2.xx>res1.xx) return res2; else return {res1.xx, (res1.yy+res2.yy)%mod}; } ll step(int sta) { if(sta==-1) return 1LL; if(sta==0) return 1LL; if(sta==1) return 2LL; ll pola=step(sta/2); pola*=pola; pola%=mod; if(sta&1) {pola*=2LL; pola%=mod;} return pola; } int main() { // ios; cin >> n; for(int i=0; i<n; ++i) { cin >> b[i].xx; b[i].yy=i; } sort(b, b+n); int dokle=1; a[b[0].yy]=1; for(int i=1; i<n; ++i) { a[b[i].yy]=(b[i-1].xx==b[i].xx?dokle:++dokle); } build(1, 1, dokle); lis[n-1].xx=lis[n-1].yy=1; upd(1, 1, dokle, a[n-1], {1, 1}); for(int i=n-2; i>=0; --i) { if(a[i]==dokle) { lis[i].xx=1; lis[i].yy=1; } else { pair<int, ll> nes=query(1, 1, dokle, a[i]+1, dokle); lis[i].xx=nes.xx+1; lis[i].yy=max(nes.yy,(ll)1); } upd(1, 1, dokle, a[i], lis[i]); } build(1, 1, dokle); lds[n-1].xx=lds[n-1].yy=1; upd(1, 1, dokle, a[n-1], {1, 1}); for(int i=n-2; i>=0; --i) { if(a[i]==1) { lds[i].xx=1; lds[i].yy=1; } else { pair<int, ll> nes=query(1, 1, dokle, 1, a[i]-1); lds[i].xx=nes.xx+1; lds[i].yy=max(nes.yy,(ll)1); } upd(1, 1, dokle, a[i], lds[i]); } int mx=0; for(int i=0; i<n; ++i) { mx=max(mx, lis[i].xx+lds[i].xx-1); } cout << mx << ' '; ll uk=0LL; ll stepen=step(n-mx); for(int i=0; i<n; ++i) { if(lis[i].xx+lds[i].xx-1!=mx) continue; //printf("%i!!! %i %i %i\n",i,lis[i].yy,lds[i].xx,lds[i].yy); uk+=lis[i].yy%mod*lds[i].yy%mod*stepen%mod; uk%=mod; } cout << uk; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...