#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 fenwick{
int n;
vector<int> bit, cnt;
fenwick(){}
fenwick(int _n) {
n = _n;
bit.resize(n + 7, -inf);
cnt.resize(n + 7, 0);
}
void update(int pos, int val, int way)
{
for(; pos <= n; pos += pos & -pos) {
if(maximize(bit[pos], val) == true) cnt[pos] = way;
else {
if(bit[pos] == val) add(cnt[pos], way);
}
}
}
pair<int, int> getans(int pos)
{
pair<int, int> res = {-1, 0};
for(; pos > 0; pos -= pos & -pos) {
if(maximize(res.fi, bit[pos]) == true) res.se = cnt[pos];
else {
if(res.fi == bit[pos]) add(res.se, cnt[pos]);
}
}
return res;
}
} ft;
int n;
int a[mxN];
pair<int, int> dp1[mxN];
pair<int, int> dp2[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;
ft = fenwick(n);
for(int i = n; i >= 1; i--) {
maximize(dp1[a[i]], make_pair(1, 1));
pair<int, int> tmp = ft.getans(a[i] - 1);
// cout << dp1[a[i]].fi << endl;
if(maximize(dp1[a[i]].fi, tmp.fi + 1) == true) {
dp1[a[i]].se = tmp.se;
}
else {
if(dp1[a[i]].fi == tmp.fi + 1)
add(dp1[a[i]].se, tmp.se);
}
ft.update(a[i], dp1[a[i]].fi, dp1[a[i]].se);
}
ft = fenwick(n);
for(int i = n; i >= 1; i--) {
maximize(dp2[a[i]], make_pair(1, 1));
pair<int, int> tmp = ft.getans(n - a[i] + 1 - 1);
if(maximize(dp2[a[i]].fi, tmp.fi + 1) == true) {
dp2[a[i]].se = tmp.se;
}
else {
if(dp2[a[i]].fi == tmp.fi + 1)
add(dp2[a[i]].se, tmp.se);
}
ft.update(n - a[i] + 1, dp2[a[i]].fi, dp2[a[i]].se);
}
pair<int, int> ans = {-1, 0};
for(int i = n; i >= 1; i--) {
if(maximize(ans.fi, dp1[a[i]].fi + dp2[a[i]].fi - 1) == true) {
ans.se = 1LL * dp1[a[i]].se * dp2[a[i]].se % mod;
}
else {
if(ans.fi == dp1[a[i]].fi + dp2[a[i]].fi - 1) {
add(ans.se, 1LL * dp1[a[i]].se * dp2[a[i]].se % mod);
}
}
}
// for(int i = 1; i <= n; i++)
// cout << dp1[a[i]].fi << ' ' << dp2[a[i]].fi << endl;
// cout << ans.se << endl;
for(int i = 1; i <= n - ans.fi; i++) ans.se = 1LL * ans.se * 2 % mod;
cout << ans.fi << ' ' << ans.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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
55 ms |
5360 KB |
Output is correct |
12 |
Correct |
53 ms |
4760 KB |
Output is correct |
13 |
Correct |
46 ms |
4416 KB |
Output is correct |
14 |
Correct |
72 ms |
4756 KB |
Output is correct |
15 |
Correct |
87 ms |
5848 KB |
Output is correct |
16 |
Correct |
101 ms |
6600 KB |
Output is correct |
17 |
Incorrect |
72 ms |
6396 KB |
Output isn't correct |
18 |
Incorrect |
72 ms |
6396 KB |
Output isn't correct |
19 |
Incorrect |
80 ms |
6452 KB |
Output isn't correct |
20 |
Incorrect |
73 ms |
6436 KB |
Output isn't correct |