# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
376332 | ja_kingy | Zoltan (COCI16_zoltan) | C++14 | 1097 ms | 24300 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.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |