# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
577256 | GioChkhaidze | Zoltan (COCI16_zoltan) | C++14 | 290 ms | 10944 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
#define lf (h << 1)
#define mf ((l + r) >> 1)
#define rf ((h << 1) | 1)
#define tree int h, int l, int r
#define left lf, l, mf
#define right rf, mf + 1, r
#define ll long long
#define pb push_back
#define f first
#define s second
using namespace std;
const int N = 2e5 + 5;
ll mod = 1e9 + 7;
int n, L, R, id, a[N];
pair < int , ll > vld, vli;
pair < int , int > vd[4 * N], vi[4 * N];
void updd(tree) {
if (r < id || id < l) return;
if (l == id && id == r) {
if (vd[h].f < vld.f) {
vd[h] = vld;
}
else
if (vd[h].f == vld.f) {
vd[h].s = (vd[h].s + vld.s) % mod;
}
return ;
}
updd(left), updd(right);
if (vd[lf].f > vd[rf].f) vd[h] = vd[lf];
else
if (vd[lf].f < vd[rf].f) vd[h] = vd[rf];
else {
vd[h].f = vd[lf].f;
vd[h].s = (vd[lf].s + vd[rf].s) % mod;
}
}
void updi(tree) {
if (r < id || id < l) return;
if (l == id && id == r) {
if (vi[h].f < vli.f) {
vi[h] = vli;
}
else
if (vi[h].f == vli.f) {
vi[h].s = (vi[h].s + vli.s) % mod;
}
return ;
}
updi(left), updi(right);
if (vi[lf].f > vi[rf].f) vi[h] = vi[lf];
else
if (vi[lf].f < vi[rf].f) vi[h] = vi[rf];
else {
vi[h].f = vi[lf].f;
vi[h].s = (vi[lf].s + vi[rf].s) % mod;
}
}
pair < int , int > geti(tree) {
if (r < L || R < l) return {0, 1};
if (L <= l && r <= R) return vi[h];
pair < int , int > x = geti(left);
pair < int , int > y = geti(right);
if (x.f > y.f) return x;
if (x.f < y.f) return y;
return {x.f, (x.s + y.s) % mod};
}
pair < int , int > getd(tree) {
if (r < L || R < l) return {0, 1};
if (L <= l && r <= R) return vd[h];
pair < int , int > x = getd(left);
pair < int , int > y = getd(right);
if (x.f > y.f) return x;
if (x.f < y.f) return y;
return {x.f, (x.s + y.s) % mod};
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
vector < pair < int , int > > s;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
s.pb({a[i], i});
}
int ts = 0;
sort(s.begin(), s.end());
for (int i = 0; i < s.size(); ++i) {
if (!i || s[i].f != s[i - 1].f) ++ts;
a[s[i].s] = ts;
}
pair < int , ll > ans = {0, 0};
for (int i = n; i >= 1; --i) {
id = a[i];
L = a[i] + 1, R = n, vld = getd(1, 1, n);
if (!vld.f) vld.s = 1; ++vld.f, updd(1, 1, n);
L = 1, R = a[i] - 1, vli = geti(1, 1, n);
if (!vli.f) vli.s = 1; ++vli.f, updi(1, 1, n);
int cst = vld.f - 1 + vli.f;
ll num = (vld.s * vli.s) % mod;
if (ans.f < cst) {
ans.f = cst;
ans.s = num;
}
else
if (ans.f == cst) {
ans.s = (ans.s + num) % mod;
}
}
for (int i = 1; i <= n - ans.f; ++i) {
ans.s = (ans.s * 2) % mod;
}
cout << ans.f << " " << ans.s << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |