Submission #376335

# Submission time Handle Problem Language Result Execution time Memory
376335 2021-03-11T09:07:37 Z ja_kingy Zoltan (COCI16_zoltan) C++14
7 / 140
243 ms 9856 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 MOD = 1e9+7, mxN = 2e5;
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) {
        //db(x); db(v.first); db(v.second); dbln;
        for (x += sz; x; x /= 2) st[x] = comb(st[x], v);
    }
    pii qry(int l, int r) {
        pii res = {0,0};
        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});
    }
    int t = 1;
    for (int i = n; i--;) {
        if (i && i-1 < pt) {
            pii res = lis.qry(mxp[i-1]+1, n);
            res = comb(res, {0,t*(a[i] < mnp[i-1] || a[i] > mxp[i-1] ? 1 : 2)%MOD});
            res.first += i;
            ans = comb(ans, res);
            res = lds.qry(0, mnp[i-1]);
            res = comb(res, {0,t*(a[i] < mnp[i-1] || a[i] > mxp[i-1] ? 1 : 2)%MOD});
            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 = comb(res, {0,t});
        res.first++;
        lis.upd(a[i], res);
        res = lds.qry(0, a[i]);
        res = comb(res, {0,t});
        res.first++;
        lds.upd(a[i], res);
        t = t * 2 % MOD;
    }
    if (ans.first == 1) ans.second = ((long long)ans.second * 500000004 + 1) % MOD;
    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:68:36: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   68 |         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 Incorrect 0 ms 364 KB Output isn't 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 1 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 120 ms 7936 KB Output isn't correct
12 Incorrect 100 ms 6764 KB Output isn't correct
13 Incorrect 95 ms 6508 KB Output isn't correct
14 Incorrect 172 ms 6912 KB Output isn't correct
15 Incorrect 177 ms 8428 KB Output isn't correct
16 Incorrect 243 ms 9836 KB Output isn't correct
17 Incorrect 141 ms 9800 KB Output isn't correct
18 Incorrect 152 ms 9772 KB Output isn't correct
19 Incorrect 138 ms 9856 KB Output isn't correct
20 Incorrect 140 ms 9836 KB Output isn't correct