# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
575214 | BackNoob | Zoltan (COCI16_zoltan) | C++14 | 251 ms | 14820 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>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
using namespace std;
const int mxN = 5e5 + 227;
const int inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
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;
}
void add(int &a, int b)
{
a += b;
if(a >= mod)
a -= mod;
}
struct IT{
int n;
vector<int> t;
vector<int> sum;
vector<int> lz;
IT(){}
IT(int _n) {
n = _n;
t.resize(n * 4 + 7, -inf);
sum.resize(n * 4 + 7, 0);
lz.resize(n * 4 + 7, 0);
}
void push_down(int v, int l, int r)
{
t[v * 2] += lz[v];
t[v * 2 + 1] += lz[v];
lz[v * 2] += lz[v];
lz[v * 2 + 1] += lz[v];
lz[v] = 0;
}
void update(int v, int tl, int tr, int l, int r, int val)
{
if(l > r) return;
if(tl == l && tr == r) {
t[v] += val;
lz[v] += val;
return;
}
else {
push_down(v, tl, tr);
int tm = (tl + tr) / 2;
update(v * 2, tl, tm, l, min(r, tm), val);
update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
t[v] = max(t[v * 2], t[v * 2 + 1]);
if(t[v * 2] == t[v * 2 + 1]) sum[v] = (sum[v * 2] + sum[v * 2 + 1]) % mod;
else {
if(t[v * 2] > t[v * 2 + 1]) sum[v] = sum[v * 2];
else sum[v] = sum[v * 2 + 1];
}
}
}
int getmax(int v, int tl, int tr, int l, int r)
{
if(l > r) return -inf;
if(tl == l && tr == r) return t[v];
push_down(v, tl, tr);
int tm = (tl + tr) / 2;
int m1 = getmax(v * 2, tl, tm, l, min(r, tm));
int m2 = getmax(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
return max(m1, m2);
}
pair<int, int> getans(int v, int tl, int tr, int l, int r)
{
if(l > r) return {-inf, 0};
if(tl == l && tr == r) return {t[v], sum[v]};
push_down(v, tl, tr);
int tm = (tl + tr) / 2;
pair<int, int> m1 = getans(v * 2, tl, tm, l, min(r, tm));
pair<int, int> m2 = getans(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
if(m1.fi == m2.fi) return {m1.fi , (m1.se + m2.se) % mod};
else {
if(m1.fi > m2.fi) return m1;
return m2;
}
}
void update_pos(int v, int tl, int tr, int pos, int val, int way)
{
if(tl == tr) {
if(maximize(t[v], val) == true) sum[v] = way;
else {
if(t[v] == val) sum[v] = (sum[v] + way) % mod;
}
}
else {
int tm = (tl + tr) / 2;
push_down(v, tl, tr);
if(pos <= tm) update_pos(v * 2, tl, tm, pos, val, way);
else update_pos(v * 2 + 1, tm + 1, tr, pos, val, way);
t[v] = max(t[v * 2], t[v * 2 + 1]);
if(t[v * 2] == t[v * 2 + 1]) sum[v] = (sum[v * 2] + sum[v * 2 + 1]) % mod;
else {
if(t[v * 2] > t[v * 2 + 1]) sum[v] = sum[v * 2];
else sum[v] = sum[v * 2 + 1];
}
}
}
void update(int l, int r, int val)
{
update(1, 1, n, l, r, val);
}
void update_pos(int pos, int val, int way)
{
update_pos(1, 1, n, pos, val, way);
}
int getmax(int l, int r)
{
return getmax(1, 1, n, l, r);
}
pair<int, int> getans(int l, int r)
{
return getans(1, 1, n, l, r);
}
} seg;
int n;
int a[mxN];
pair<int, int> dp[mxN];
void solve()
{
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
vector<int> val;
for(int i = 1; i <= n; i++) val.pb(a[i]);
sort(all(val));
val.erase(unique(all(val)), val.end());
for(int i = 1; i <= n; i++)
a[i] = lower_bound(all(val), a[i]) - val.begin() + 1;
seg = IT(n);
int s = 1;
for(int i = 1; i <= n; i++) {
maximize(dp[a[i]], make_pair(1, 1));
seg.update(a[i] + 1, n, 1);
pair<int, int> tmp = seg.getans(1, a[i] - 1);
if(maximize(dp[a[i]].fi, tmp.fi + 1) == true){
dp[a[i]].se = tmp.se;
}
// cout << dp[a[i]].fi << ' ' << dp[a[i]].se << endl;
seg.update_pos(a[i], dp[a[i]].fi, dp[a[i]].se);
// cout << seg.getmax(1, n) << endl;
s *= 2;
}
pair<int, int> res = seg.getans(1, n);
for(int i = 1; i <= n - res.fi; i++) res.se = 1LL * res.se * 2 % mod;
cout << res.fi << ' ' << res.se << endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen(TASK".in" , "r" , stdin);
//freopen(TASK".out" , "w" , stdout);
int tc = 1;
// cin >> tc;
while(tc--) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |