#include<bits/stdc++.h>
using namespace std;
const bool multiTest = false;
#define task "C"
#define fi first
#define se second
#define MASK(i) (1LL << (i))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define BIT(mask, i) ((mask) >> (i) & 1)
template<typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) a = b; else return 0; return 1;
}
template<typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) a = b; else return 0; return 1;
}
const int MOD = 1e9 + 7;
const int MAX = 200020;
int N;
int A[MAX];
vector<int> values;
pair<int, int> f[MAX];
pair<int, int> g[MAX];
void add(int &x, const int &y) {
x += y;
if (x >= MOD) x -= MOD;
}
void update(pair<int, int> &res, const pair<int, int> &value) {
if (res.fi < value.fi) {
res = value;
} else {
if (res.fi == value.fi) {
add(res.se, value.se);
}
}
}
void updateF(int id, const pair<int, int> &value) {
for (; id > 0; id -= id & -id)
update(f[id], value);
}
pair<int, int> getF(int id) {
pair<int, int> res(0, 1);
for (; id <= N; id += id & -id)
update(res, f[id]);
return res;
}
void setF() {
for (int i = 1; i <= N; ++i) f[i] = {0, 0};
}
void updateG(int id, const pair<int, int> &value) {
for (; id <= N; id += id & -id)
update(g[id], value);
}
pair<int, int> getG(int id) {
pair<int, int> res(0, 1);
for (; id > 0; id -= id & -id)
update(res, g[id]);
return res;
}
void setG() {
for (int i = 1; i <= N; ++i) g[i] = {0, 0};
}
void process(void) {
cin >> N;
for (int i = 1; i <= N; ++i) {
cin >> A[i];
values.push_back(A[i]);
}
sort(all(values)); values.resize(unique(all(values)) - values.begin());
for (int i = 1; i <= N; ++i) {
A[i] = lower_bound(all(values), A[i]) - values.begin() + 1;
}
pair<int, int> res(0, 1);
setF();
setG();
for (int i = N; i >= 1; --i) {
pair<int, int> ff = getF(A[i] + 1);
pair<int, int> gg = getG(A[i] - 1);
pair<int, int> mg(ff.fi + gg.fi + 1, 1LL * ff.se * gg.se % MOD);
update(res, mg);
ff.fi += 1; updateF(A[i], ff);
gg.fi += 1; updateG(A[i], gg);
}
for (int i = N - res.fi; i >= 1; --i) {
res.se = 2LL * res.se % MOD;
}
cout << res.fi << ' ' << res.se;
}
int main(void) {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int nTest = 1; if (multiTest) cin >> nTest;
while (nTest--) {
process();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
zoltan.cpp: In function 'int main()':
zoltan.cpp:111:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
111 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
zoltan.cpp:112:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
112 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |