답안 #459193

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
459193 2021-08-08T10:12:38 Z nikolapesic2802 Zoltan (COCI16_zoltan) C++14
91 / 140
405 ms 15736 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=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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 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 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Incorrect 240 ms 13944 KB Output isn't correct
12 Correct 234 ms 13360 KB Output is correct
13 Correct 193 ms 8868 KB Output is correct
14 Correct 256 ms 13540 KB Output is correct
15 Incorrect 377 ms 14752 KB Output isn't correct
16 Incorrect 405 ms 15736 KB Output isn't correct
17 Incorrect 305 ms 15132 KB Output isn't correct
18 Incorrect 314 ms 15232 KB Output isn't correct
19 Incorrect 324 ms 15176 KB Output isn't correct
20 Incorrect 308 ms 15256 KB Output isn't correct