Submission #680485

# Submission time Handle Problem Language Result Execution time Memory
680485 2023-01-11T00:54:41 Z GusterGoose27 Zoltan (COCI16_zoltan) C++11
140 / 140
430 ms 24316 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e5;
const int MOD = 1e9+7;
int n;
int seq[MAXN];
map<int, int> compress;
typedef pair<int, int> pii;
typedef long long ll;
int t = 0;

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

class stree {
public:
	stree *l = nullptr;
	stree *r = nullptr;
	pii mx = pii(0, 0);
	stree(int lv, int rv) {
		if (lv < rv) {
			int mid = (lv+rv)/2;
			l = new stree(lv, mid);
			r = new stree(mid+1, rv);
		}
	}
	void upd(int p, pii v, int lp = 0, int rp = t-1) {
		if (lp > p || rp < p) return;
		if (lp == rp) {
			mx = comb(mx, v);
			return;
		}
		int mid = (lp+rp)/2;
		l->upd(p, v, lp, mid);
		r->upd(p, v, mid+1, rp);
		mx = comb(l->mx, r->mx);
	}
	void reset() {
		mx = pii(0, 0);
		if (l) {
			l->reset();
			r->reset();
		}
	}
	pii query(int lv, int rv, int lp = 0, int rp = t-1) {
		if (lp >= lv && rp <= rv) return mx;
		if (lp > rv || rp < lv) return pii(0, 0);
		int mid = (lp+rp)/2;
		return comb(l->query(lv, rv, lp, mid), r->query(lv, rv, mid+1, rp));
	}
};

stree *tree;
pii upseq[MAXN];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> seq[i];
		compress[seq[i]] = 0;
	}
	for (auto it = compress.begin(); it != compress.end();) {
		int v = it->first;
		it++;
		compress[v] = t++;
	}
	for (int i = 0; i < n; i++) seq[i] = compress[seq[i]];
	tree = new stree(0, t-1);
	pii ans(0, 0);
	for (int i = n-1; i >= 0; i--) {
		upseq[i] = tree->query(seq[i]+1, t-1);
		upseq[i].first++;
		if (upseq[i].second == 0) upseq[i].second++;
		tree->upd(seq[i], upseq[i]);
	}
	tree->reset();
	for (int i = n-1; i >= 0; i--) {
		pii downseq = tree->query(0, seq[i]-1);
		downseq.first++;
		if (downseq.second == 0) downseq.second++;
		tree->upd(seq[i], downseq);
		ans = comb(ans, pii(upseq[i].first+downseq.first-1, ((ll)upseq[i].second*downseq.second)%MOD));
	}
	for (int i = 0; i < n-ans.first; i++) ans.second = (2*ans.second)%MOD;
	cout << ans.first << " " << ans.second << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 239 ms 19492 KB Output is correct
12 Correct 208 ms 17004 KB Output is correct
13 Correct 175 ms 15980 KB Output is correct
14 Correct 290 ms 17036 KB Output is correct
15 Correct 369 ms 21112 KB Output is correct
16 Correct 430 ms 24316 KB Output is correct
17 Correct 335 ms 20996 KB Output is correct
18 Correct 224 ms 20968 KB Output is correct
19 Correct 258 ms 20996 KB Output is correct
20 Correct 273 ms 21008 KB Output is correct