Submission #376332

# Submission time Handle Problem Language Result Execution time Memory
376332 2021-03-11T08:58:44 Z ja_kingy Zoltan (COCI16_zoltan) C++14
0 / 140
1000 ms 24300 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) {
        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*2%MOD});
            res.first += i;
            ans = comb(ans, res);
            res = lds.qry(0, mnp[i-1]);
            res = comb(res, {0,t*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 1 ms 364 KB Output isn't correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Incorrect 7 ms 492 KB Output isn't correct
8 Incorrect 7 ms 492 KB Output isn't correct
9 Incorrect 7 ms 492 KB Output isn't correct
10 Incorrect 7 ms 492 KB Output isn't correct
11 Execution timed out 1039 ms 22480 KB Time limit exceeded
12 Incorrect 914 ms 19540 KB Output isn't correct
13 Incorrect 839 ms 18528 KB Output isn't correct
14 Incorrect 931 ms 19820 KB Output isn't correct
15 Execution timed out 1094 ms 23276 KB Time limit exceeded
16 Execution timed out 1091 ms 24300 KB Time limit exceeded
17 Execution timed out 1077 ms 23508 KB Time limit exceeded
18 Execution timed out 1096 ms 23660 KB Time limit exceeded
19 Execution timed out 1090 ms 23660 KB Time limit exceeded
20 Execution timed out 1097 ms 23404 KB Time limit exceeded