제출 #940691

#제출 시각아이디문제언어결과실행 시간메모리
94069112345678Zoltan (COCI16_zoltan)C++17
0 / 140
442 ms49200 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int nx=2e5+5, mod=1e9+7; ll n, v[nx], t, p[nx]; map<ll, ll> mp; struct node { ll mx, w; node(ll mx=0, ll w=1): mx(mx), w(w) {} friend node operator+(const node &a, const node &b) { node res; res.mx=max(a.mx, b.mx); if (a.mx==b.mx) res.w=(a.w+b.w)%mod; else res.w=(a.mx>b.mx)?a.w:b.w; if (res.mx==0) res.w=1; return res; } } ans, dpi[nx], dpd[nx]; struct segtree { node d[4*nx]; void update(int l, int r, int i, int idx, node vl) { if (idx<l||r<idx) return; if (l==r) return d[i]=d[i]+vl, void(); int md=(l+r)/2; update(l, md, 2*i, idx, vl); update(md+1, r, 2*i+1, idx, vl); d[i]=d[2*i]+d[2*i+1]; } node query(int l, int r, int i, int ql, int qr) { if (r<ql||qr<l) return node(); if (ql<=l&&r<=qr) return d[i]; int md=(l+r)/2; return query(l, md, 2*i, ql, qr)+query(md+1, r, 2*i+1, ql, qr); } } lis, lds; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n; p[0]=1; for (int i=1; i<=n; i++) p[i]=(p[i-1]*2)%mod; for (int i=1; i<=n; i++) cin>>v[i], mp[v[i]]=0; for (auto &[x, y]:mp) y=++t; for (int i=n; i>=1; i--) { node a=lis.query(1, n, 1, mp[v[i]]+1, n); node b=lds.query(1, n, 1, 1, mp[v[i]]-1); a.mx++; b.mx++; dpi[i]=a; dpd[i]=b; lis.update(1, n, 1, mp[v[i]], a); lds.update(1, n, 1, mp[v[i]], b); } for (int i=1; i<=n; i++) { node tmp; tmp.mx=dpi[i].mx+dpd[i].mx-1; tmp.w=(p[n-tmp.mx]*tmp.w)%mod; tmp.w=((tmp.w*dpi[i].w)%mod*dpd[i].w)%mod; //cout<<"here "<<i<<' '<<tmp.mx<<' '<<tmp.w<<'\n', cout<<i<<' '<<dpi[i].mx<<' '<<dpi[i].w<<' '<<dpd[i].mx<<' '<<dpd[i].w<<'\n'; ans=ans+tmp; } cout<<ans.mx<<' '<<ans.w; //for (int i=1; i<=n; i++) cout<<i<<' '<<dpi[i].mx<<' '<<dpi[i].w<<' '<<dpd[i].mx<<' '<<dpd[i].w<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...