#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
const int maxn = 200010;
const int INF = LLONG_MAX/2;
const int mod = 1e9+7;
int mx;
pi calc(pi a, pi b) {
if (a.f == b.f) return pi(a.f, (a.s + b.s) % mod);
else return max(a, b);
}
pi fw1[maxn], fw2[maxn];
int ls(int x) {
return x & (-x);
}
void upd(pi *fw, int x, pi nv) {
for (; x <= mx; x+=ls(x)) fw[x] = calc(fw[x], nv);
}
pi sum(pi *fw, int x) {
pi res = pi(0,0);
for (; x; x -= ls(x)) res = calc(res, fw[x]);
return res;
}
int n;
int A[maxn];
int32_t main() {
FAST
// ifstream cin("input.txt");
cin >> n;
vector <int> v;
for (int i = 1; i <= n;i++) {
cin >> A[i];
v.push_back(A[i]);
}
sort(all(v));
v.resize(unique(v.begin(),v.end()) - v.begin());
for (int i = 1; i<=n;i++) {
A[i] = lower_bound(all(v), A[i]) - v.begin() + 1;
}
mx = v.size()+1;
pi rans = pi(0,0);
for (int i = n; i >= 1; i--) {
pi aft = sum(fw1, mx - (A[i] + 1));
pi bef = sum(fw2, A[i] - 1);
if (aft.s == 0) aft.s = 1;
aft.f += 1;
upd(fw1, mx - A[i], aft);
if (bef.s == 0) bef.s = 1;
bef.f += 1;
upd(fw2, A[i], bef);
rans = calc(rans, pi(bef.f + aft.f - 1, bef.s * aft.s));
}
for (int i = 0; i < n - rans.f; i++) {
rans.s *= 2;
rans.s %= mod;
}
cout << rans.f << " " << rans.s << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
212 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 |
60 ms |
7812 KB |
Output is correct |
12 |
Correct |
56 ms |
6872 KB |
Output is correct |
13 |
Correct |
51 ms |
6448 KB |
Output is correct |
14 |
Correct |
72 ms |
6844 KB |
Output is correct |
15 |
Correct |
101 ms |
8388 KB |
Output is correct |
16 |
Correct |
105 ms |
9704 KB |
Output is correct |
17 |
Correct |
75 ms |
8716 KB |
Output is correct |
18 |
Correct |
77 ms |
8724 KB |
Output is correct |
19 |
Correct |
97 ms |
8768 KB |
Output is correct |
20 |
Correct |
85 ms |
8704 KB |
Output is correct |