//Copyright © 2022 Youngmin Park. All rights reserved.
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpi = vector<pii>;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vpl = vector<pll>;
using ld = long double;
template <typename T, size_t SZ>
using ar = array<T, SZ>;
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define REP(a) F0R(_, a)
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7; //998244353;
const ld PI = acos((ld)-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <typename T>
bool ckmax(T &a, const T &b) { return b > a ? a = b, 1 : 0; }
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v)
{
os << '{';
string sep;
for (const T &x : v)
os << sep << x, sep = ", ";
return os << '}';
}
void dbg_out()
{
cerr << endl;
}
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
cerr << ' ' << H;
dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif
inline namespace RecursiveLambda{
template <typename Fun>
struct y_combinator_result{
Fun fun_;
template <typename T>
explicit y_combinator_result(T &&fun): fun_(forward<T>(fun)){}
template <typename...Args>
decltype(auto) operator()(Args &&...args){
return fun_(ref(*this), forward<Args>(args)...);
}
};
template <typename Fun>
decltype(auto) y_combinator(Fun &&fun){
return y_combinator_result<decay_t<Fun>>(forward<Fun>(fun));
}
};
void setIO(string s) // USACO
{
#ifndef LOCAL
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
#endif
}
/**
* Description: modular arithmetic operations
* Source:
* KACTL
* https://codeforces.com/blog/entry/63903
* https://codeforces.com/contest/1261/submission/65632855 (tourist)
* https://codeforces.com/contest/1264/submission/66344993 (ksun)
* also see https://github.com/ecnerwala/cp-book/blob/master/src/modnum.hpp (ecnerwal)
* Verification:
* https://open.kattis.com/problems/modulararithmetic
*/
template<int MOD, int RT> struct mint {
static const int mod = MOD;
static constexpr mint rt() { return RT; } // primitive root for FFT
int v; explicit operator int() const { return v; } // explicit -> don't silently convert to int
mint() { v = 0; }
mint(ll _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD);
if (v < 0) v += MOD; }
bool operator==(const mint& o) const{
return v == o.v; }
friend bool operator!=(const mint& a, const mint& b) {
return !(a == b); }
friend bool operator<(const mint& a, const mint& b) {
return a.v < b.v; }
friend istream& operator>>(istream& is, const mint& o){
ll v; is >> v; o = mint(v); return is; }
friend ostream& operator<<(ostream& os, const mint& o){
os << o.v; return os; }
mint& operator+=(const mint& m) {
if ((v += m.v) >= MOD) v -= MOD;
return *this; }
mint& operator-=(const mint& m) {
if ((v -= m.v) < 0) v += MOD;
return *this; }
mint& operator*=(const mint& m) {
v = int((ll)v*m.v%MOD); return *this; }
mint& operator/=(const mint& m) { return (*this) *= inv(m); }
friend mint pow(mint a, ll p) {
mint ans = 1; assert(p >= 0);
for (; p; p /= 2, a *= a) if (p&1) ans *= a;
return ans; }
friend mint inv(const mint& a) { assert(a.v != 0);
return pow(a,MOD-2); }
mint operator-() const { return mint(-v); }
mint& operator++() { return *this += 1; }
mint& operator--() { return *this -= 1; }
friend mint operator+(mint a, const mint& b) { return a += b; }
friend mint operator-(mint a, const mint& b) { return a -= b; }
friend mint operator*(mint a, const mint& b) { return a *= b; }
friend mint operator/(mint a, const mint& b) { return a /= b; }
};
using Mint = mint<MOD,5>; // 5 is primitive root for both common mods
template<typename T, typename Merge = plus<T>>
struct SegTree{
int sz;
const Merge merge;
vector<T> t;
SegTree(int n) : merge(Merge()) {
sz = 1;
while (sz<n) sz*=2;
t.resize(sz*2);
}
void build(vector<T> &vec, int x, int l, int r)
{
if (r - l == 1)
{
if (l < (int)vec.size())
t[x] = vec[l];
return;
}
int mid = (l + r) / 2;
build(vec, 2 * x + 1, l, mid);
build(vec, 2 * x + 2, mid, r);
t[x] = merge(t[2 * x + 1], t[2 * x + 2]);
}
void build(vector<T> &vec)
{
build(vec, 0, 0, sz);
}
void upd(int i, const T& v, int x, int l, int r)
{
if (r - l == 1)
{
t[x] = merge(t[x], v);
return;
}
int mid = (l + r) / 2;
if (i < mid)
upd(i, v, 2 * x + 1, l, mid);
else
upd(i, v, 2 * x + 2, mid, r);
t[x] = merge(t[2 * x + 1], t[2 * x + 2]);
}
void upd(int i, const T& v)
{
upd(i, v, 0, 0, sz);
}
T query(int l, int r, int x, int lx, int rx)
{
if (lx >= r || rx <= l)
return T();
if (lx >= l && rx <= r)
return t[x];
int mid = (lx + rx) / 2;
T a = query(l, r, 2 * x + 1, lx, mid);
T b = query(l, r, 2 * x + 2, mid, rx);
return merge(a, b);
}
T query(int l, int r)
{
return query(l, r, 0, 0, sz);
}
};
struct Max {
int len;
Mint cnt;
Max(int x = 0, Mint c = 1) : len(x), cnt(c) {}
Max operator+(const Max& other) const {
if (other.len > len) return other;
if (len > other.len) return *this;
return {len, cnt + other.cnt};
}
};
void solve()
{
int n;
cin >> n;
vi a(n), tmp;
for (int &e : a) cin >> e, tmp.pb(e);
sort(all(tmp));
tmp.resize(unique(all(tmp)) - tmp.begin());
for (auto &e : a) e = lb(all(tmp), e) - tmp.begin();
Mint ans = 0;
int mx = 0;
SegTree<Max> smax(sz(tmp)), smin(sz(tmp));
R0F(i, n) {
auto &e = a[i];
Max z = smax.query(e + 1, sz(tmp)), w = smin.query(0, e);
int len = z.len + w.len + 1;
if (i == 0) {
ans /= 2;
if (ckmax(mx, len)) {
ans = z.cnt * w.cnt;
}else if (mx == len) ans += z.cnt * w.cnt;
break;
}
if (ckmax(mx, len)) {
ans = z.cnt * w.cnt * 2;
}else if (mx == len) ans += z.cnt * w.cnt * 2;
z.len++;
w.len++;
dbg(i, e, w.len, z.len);
smax.upd(e, z);
smin.upd(e, w);
}
cout << mx << ' ' << ans * pow(Mint(2), n - mx) << '\n';
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int testcase=1;
// cin >> testcase;
while (testcase--)
{
solve();
}
}
Compilation message
zoltan.cpp: In function 'void solve()':
zoltan.cpp:71:18: warning: statement has no effect [-Wunused-value]
71 | #define dbg(...) 42
| ^~
zoltan.cpp:257:3: note: in expansion of macro 'dbg'
257 | dbg(i, e, w.len, z.len);
| ^~~
zoltan.cpp: In function 'void setIO(std::string)':
zoltan.cpp:94:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
94 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
zoltan.cpp:95:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
95 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Incorrect |
151 ms |
10404 KB |
Output isn't correct |
12 |
Incorrect |
130 ms |
10320 KB |
Output isn't correct |
13 |
Incorrect |
120 ms |
6148 KB |
Output isn't correct |
14 |
Incorrect |
169 ms |
10316 KB |
Output isn't correct |
15 |
Incorrect |
217 ms |
10644 KB |
Output isn't correct |
16 |
Incorrect |
244 ms |
10800 KB |
Output isn't correct |
17 |
Incorrect |
199 ms |
10824 KB |
Output isn't correct |
18 |
Incorrect |
192 ms |
10824 KB |
Output isn't correct |
19 |
Incorrect |
197 ms |
10820 KB |
Output isn't correct |
20 |
Incorrect |
198 ms |
10908 KB |
Output isn't correct |