Submission #459213

# Submission time Handle Problem Language Result Execution time Memory
459213 2021-08-08T10:41:12 Z nikolapesic2802 Zoltan (COCI16_zoltan) C++14
140 / 140
361 ms 14008 KB
#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=0LL; 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+=val.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 time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 304 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 237 ms 12868 KB Output is correct
12 Correct 200 ms 12340 KB Output is correct
13 Correct 182 ms 7952 KB Output is correct
14 Correct 267 ms 12288 KB Output is correct
15 Correct 355 ms 13244 KB Output is correct
16 Correct 361 ms 14008 KB Output is correct
17 Correct 299 ms 13904 KB Output is correct
18 Correct 296 ms 13892 KB Output is correct
19 Correct 278 ms 13884 KB Output is correct
20 Correct 290 ms 14004 KB Output is correct