Submission #780240

#TimeUsernameProblemLanguageResultExecution timeMemory
780240chanhchuong123Zoltan (COCI16_zoltan)C++14
140 / 140
95 ms7744 KiB
#include <bits/stdc++.h>
using namespace std;
#define task ""
#define fi first
#define se second
#define MASK(i) (1LL << (i))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define BIT(mask, i) ((mask) >> (i) & 1)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (b), _a = (a); i >= _a; --i)

template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}

const int dx[] = {-1, 0, 0, +1};
const int dy[] = {0, -1, +1, 0};

const int MOD = 1e9 + 7;
const int MAX = 200200;
int n;
int a[MAX];
int pw[MAX];
vector<int> tmp;

pair<int, int> combine(const pair<int, int> &u, const pair<int, int> &v) {
    if (u.fi > v.fi) return u;
    if (u.fi < v.fi) return v;
    return make_pair(u.fi, (u.se + v.se) % MOD);
}

pair<int, int> f[MAX], g[MAX];
void update(pair<int, int> bit[], int id, const pair<int, int> &value) {
    for (; id <= n; id += id & -id) bit[id] = combine(bit[id], value);
}
pair<int, int> get(pair<int, int> bit[], int id) {
    pair<int, int> res(0, 1);
    for (; id > 0; id -= id & -id) res = combine(res, bit[id]);
    ++res.fi;     return res;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);

	if (fopen(task".inp", "r")) {
		freopen(task".inp", "r", stdin);
		freopen(task".out", "w", stdout);
	}


    cin >> n;
    pw[0] = 1;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        tmp.push_back(a[i]);
        pw[i] = 2LL * pw[i - 1] % MOD;
    }
    sort(all(tmp));
    tmp.resize(unique(all(tmp)) - tmp.begin());

    int ans = 0, cnt = 0;
    for (int i = n; i >= 1; --i) {
        a[i] = upper_bound(all(tmp), a[i]) - tmp.begin();
        pair<int, int> inc = get(f, a[i] - 1);
        pair<int, int> dec = get(g, n - a[i]);
        int len = inc.fi + dec.fi - 1;
        if (len > ans) {
            ans = len;
            cnt = 1LL * inc.se * dec.se % MOD;
        } else if (len == ans) {
            cnt = (cnt + 1LL * inc.se * dec.se % MOD) % MOD;
        }
        update(f, a[i], inc);
        update(g, n - a[i] + 1, dec);
    }
    cout << ans << ' ' << 1LL * cnt * pw[n - ans] % MOD;

	return 0;
}

Compilation message (stderr)

zoltan.cpp: In function 'int main()':
zoltan.cpp:50:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
zoltan.cpp:51:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...