# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
547617 | Soul234 | Zoltan (COCI16_zoltan) | C++14 | 105 ms | 14784 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>
using namespace std;
void DBG() { cerr << "]\n"; }
template<class H, class... T> void DBG(H h, T... t) {
cerr << h; if(sizeof...(t)) cerr << ", ";
DBG(t...);
}
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif // LOCAL
#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 each(e,a) for(auto &e : (a))
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb push_back
#define tcT template<class T
#define nl "\n"
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using str = string;
tcT> using V = vector<T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;
void setIO(string NAME = "") {
cin.tie(0)->sync_with_stdio(0);
if(sz(NAME)) {
freopen((NAME + ".inp").c_str(),"r",stdin);
freopen((NAME + ".out").c_str(),"w",stdout);
}
}
#define f first
#define s second
const int MOD = 1e9 + 7;
int add(int a, int b) {
if((a += b) >= MOD) a-=MOD;
return a;
}
int mul(int a, int b) {
return 1LL*a*b%MOD;
}
const int MX = 4e5+5;
V<pi> ft1(MX, {0,0}), ft2(MX, {0,0});
int N, A[MX], pw2[MX]; vi compr;
pi Dec[MX], Inc[MX];
pi comb(const pi&a, const pi&b) {
if(a.f == b.f) return {a.f, add(a.s, b.s)};
return max(a, b);
}
pi query1(int p) {
pi res = {0,0};
for(p += 5; p; p -= p&-p) res = comb(res, ft1[p]);
return res;
}
void upd1(int p, pi val) {
for(p+=5; p<MX; p += p&-p) ft1[p] = comb(ft1[p], val);
}
pi query2(int p) {
pi res = {0,0};
for(p += 5; p<MX; p += p&-p) res = comb(res, ft2[p]);
return res;
}
void upd2(int p, pi val) {
for(p+=5; p; p -= p&-p) ft2[p] = comb(ft2[p], val);
}
void solve() {
pw2[0] = 1;
FOR(i,1,MX) pw2[i] = mul(pw2[i-1], 2);
cin>>N;
F0R(i,N) {
cin>>A[i];
compr.pb(A[i]);
}
sort(all(compr)); compr.erase(unique(all(compr)), compr.end());
F0R(i,N) {
A[i] = lower_bound(all(compr), A[i]) - begin(compr) + 1;
}
R0F(i,N) {
pi tmp = query1(A[i]-1);
if(tmp.f == 0) {
Dec[i] = {0, 1};
tmp = {1,1};
}
else {
Dec[i] = tmp;
tmp.f++;
}
upd1(A[i], tmp);
}
R0F(i,N) {
pi tmp = query2(A[i]+1);
if(tmp.f == 0) {
Inc[i] = {0, 1};
tmp = {1,1};
}
else {
Inc[i] = tmp;
tmp.f++;
}
upd2(A[i], tmp);
}
pi ans = {0,0};
//dbg(Dec[0].f, Dec[0].s, Inc[0].f, Inc[0].s);
F0R(i,N) {
ans = comb(ans, {Inc[i].f + Dec[i].f + 1, mul(Inc[i].s, Dec[i].s) });
}
ans.s = mul(ans.s, pw2[N-ans.f]);
cout << ans.f << " " << ans.s << nl;
}
int main() {
setIO();
int t=1;
//cin>>t;
while(t-->0) {
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |