Submission #376327

# Submission time Handle Problem Language Result Execution time Memory
376327 2021-03-11T08:41:51 Z ja_kingy Zoltan (COCI16_zoltan) C++14
14 / 140
227 ms 9836 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int,int> pii;
using vi = vector<int>;
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define LOG2(x)(31-__builtin_clz(x|1))
#define rep(i, a, b) for (__typeof(a) i = a; i < b; i++)
#define repe(i, a, b) for (__typeof(a) i = a; i <= b; i++)

// Debugging
template <typename T> string arrayStr(T *arr,int sz){string ret = "[";for(int i=0;i<sz;i++){ret+=to_string(arr[i])+", "; } return ret + "]";}
#define db(x) cout << (#x) << ": " << x << ", "
#define dbbin(x, n) cout << (#x) << ": " << bitset<n>(x) << ", "
#define dbarr(x, n) cout << (#x) << ": " << arrayStr((x), (n)) << ", "
#define dbvec(x) dbarr((x).data(),sz(x))
#define dbln cout << endl;

const int mxN = 2e5, MOD = 1e9+7;
int n, a[mxN], ord[mxN], mnp[mxN], mxp[mxN], pt, pfx[mxN];
pii ans;

pii comb(pii a, pii b) {
    if (a.first != b.first) {
        return max(a,b);
    } else {
        return {a.first, (a.second + b.second) % MOD};
    }
}

struct ST {
    vector<pii> st;
    int sz;
    ST(int sz) : sz(sz), st(sz*2) {}
    void upd(int x, pii v) {
        for (x += sz; x; x /= 2) st[x] = comb(st[x], v);
    }
    pii qry(int l, int r) {
        pii res = {0,1};
        for (l += n, r += n; l < r; l /= 2, r /= 2) {
            if (l&1) res = comb(res, st[l++]);
            if (r&1) res = comb(res, st[--r]);
        }
        return res;
    }
};

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        ord[i] = a[i];
    }
    sort(ord, ord+n);
    for (int i = 0; i < n; ++i) {
        a[i] = lower_bound(ord, ord+n, a[i]) - ord;
    }
    int mn = mxN, mx = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] < mn || a[i] > mx && pt == i) {
            pt++;
        }
        mn = min(mn, a[i]);
        mx = max(mx, a[i]);
        mnp[i] = mn;
        mxp[i] = mx;
    }
    ST lis(n), lds(n);
    if (pt == n) {
        ans = comb(ans, {n, 1});
    }
    for (int i = n; i--;) {
        if (i && i-1 < pt) {
            pii res = lis.qry(mxp[i-1]+1, n);
            res.first += i;
            ans = comb(ans, res);
            res = lds.qry(0, mnp[i-1]);
            res.first += i;
            ans = comb(ans, res);
        }
        if (i == 0) {
            ans = comb(ans, lis.qry(0, n));
            ans = comb(ans, lds.qry(0, n));
        }
        pii res = lis.qry(a[i]+1, n);
        res.first++;
        lis.upd(a[i], res);
        res = lds.qry(0, a[i]);
        res.first++;
        lds.upd(a[i], res);
    }
    cout << ans.first << ' ' << ans.second;
}

Compilation message

zoltan.cpp: In constructor 'ST::ST(int)':
zoltan.cpp:38:9: warning: 'ST::sz' will be initialized after [-Wreorder]
   38 |     int sz;
      |         ^~
zoltan.cpp:37:17: warning:   'std::vector<std::pair<int, int> > ST::st' [-Wreorder]
   37 |     vector<pii> st;
      |                 ^~
zoltan.cpp:39:5: warning:   when initialized here [-Wreorder]
   39 |     ST(int sz) : sz(sz), st(sz*2) {}
      |     ^~
zoltan.cpp: In function 'int main()':
zoltan.cpp:67:36: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   67 |         if (a[i] < mn || a[i] > mx && pt == i) {
      |                          ~~~~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Incorrect 1 ms 364 KB Output isn't correct
8 Incorrect 2 ms 364 KB Output isn't correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Incorrect 1 ms 364 KB Output isn't correct
11 Incorrect 113 ms 7788 KB Output isn't correct
12 Incorrect 95 ms 6764 KB Output isn't correct
13 Incorrect 93 ms 6380 KB Output isn't correct
14 Incorrect 153 ms 6892 KB Output isn't correct
15 Incorrect 184 ms 8428 KB Output isn't correct
16 Incorrect 227 ms 9708 KB Output isn't correct
17 Incorrect 143 ms 9708 KB Output isn't correct
18 Incorrect 146 ms 9836 KB Output isn't correct
19 Incorrect 144 ms 9836 KB Output isn't correct
20 Incorrect 137 ms 9708 KB Output isn't correct