답안 #577245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
577245 2022-06-14T10:32:59 Z Ronin13 Zoltan (COCI16_zoltan) C++14
91 / 140
380 ms 32500 KB
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;

const ll mod = 1e9 + 7;

map <int, int> mp;
const int NMAX = 2e5 + 1;

pll t[4 * NMAX][2];

pll combine(pll a, pll  b){
    if(a.f == b.f) return {a.f, (a.s + b.s) % mod};
    if(a.f > b.f) return a;
    return b;
}

int n;

void build(int v, int l, int r){
    if(l == r){
        if(l == n + 2) {
            t[v][0].s = 1;
        }
        if(l == 1){
            t[v][1].s = 1;
        }
        return;
    }
    int m = (l + r) / 2;
    build(2 * v, l, m);
    build(2 * v + 1, m + 1, r);
    t[v][0] = combine(t[2 * v][0], t[2 * v + 1][0]);
    t[v][1] = combine(t[2 * v][1], t[2 * v + 1][1]);
}

pll get(int v, int l, int r, int st, int fin, int ind){
    if(l > fin || r < st) return {-1, -1};
    if(l >= st && r <= fin) return t[v][ind];
    int m = (l + r) / 2;
    pll x = get(2 * v, l, m, st, fin, ind);
    pll y = get(2 * v + 1, m + 1, r, st, fin, ind);
    return combine(x, y);
}


void update(int v, int l, int r, int pos, pll val, int ind){
    if(l > pos || r < pos) return;
    if(l == r){
        t[v][ind] = val;
        return;
    }
    int m = (l + r) / 2;
    update(2 * v, l, m, pos, val, ind);
    update(2 * v + 1, m + 1, r, pos, val, ind);
    t[v][ind] = combine(t[2 * v][ind], t[2 * v + 1][ind]);
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    int a[n + 1];
    pii b[n + 1];
    for(int i = 1; i <= n ; i++){
        cin >> a[i];
        b[i] = {a[i], i};
    }
    sort(b + 1, b + 1 + n);
    for(int i = 1; i <= n; i++){
        mp[b[i].f] = i + 1;
    }
    for(int i = 1; i <= n; i++){
        a[i] = mp[a[i]];
    }
    build(1, 1, n + 2);
    pll ans[n + 1];
    ll mx = 0;
    ll cnt = 0;
    for(int i = n; i >= 1; i--){
        pll x = get(1, 1, n + 2, 1, a[i] - 1, 1);
        pll y = get(1, 1, n + 2, a[i] + 1, n + 2, 0);
        ans[i] = {x.f + y.f + 1, x.s * y.s % mod};
        update(1, 1, n + 1, a[i], {x.f + 1, x.s}, 1);
        update(1, 1, n + 1, a[i], {y.f + 1, y.s}, 0);
        mx = max(mx, ans[i].f);
    }
    for(int i = 1; i <= n; i++){
        if(mx == ans[i].f){
            cnt += ans[i].s;
            cnt %= mod;
        }
    }
    for(int i = 1; i <= n - mx; i++){
        cnt *= 2;
        cnt %= mod;
    }
    cout << mx << ' ' << cnt << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Correct 1 ms 468 KB Output is correct
8 Incorrect 1 ms 468 KB Output isn't correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 220 ms 29484 KB Output is correct
12 Correct 226 ms 27920 KB Output is correct
13 Correct 167 ms 19116 KB Output is correct
14 Correct 235 ms 27988 KB Output is correct
15 Incorrect 314 ms 30488 KB Output isn't correct
16 Incorrect 380 ms 32500 KB Output isn't correct
17 Incorrect 265 ms 31040 KB Output isn't correct
18 Incorrect 267 ms 31180 KB Output isn't correct
19 Correct 350 ms 31052 KB Output is correct
20 Incorrect 281 ms 30984 KB Output isn't correct