# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
446334 | LptN21 | Zoltan (COCI16_zoltan) | C++14 | 444 ms | 17104 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;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define FF first
#define SS second
#define pb push_back
#define sz(x) (int)x.size()
//#define oo 2e18
#define eps 1e-9
#define PI acos(-1.0)
#define lb lower_bound
#define ub upper_bound
#define all(a) (a).begin(), (a).end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> i3;
const int N = 4e5+7, M=1e6;
const int MOD = 1e9+7;
const int oo=1e9+1;
int n, m, k, t;
struct Node{
ii v;
Node() {v=ii(0, 0);}
Node(int f, int s) {v=ii(f, s);}
} st[N<<2];
ii add(ii a, ii b) {
if(a.FF>b.FF) return a;
else if(a.FF<b.FF) return b;
return ii(a.FF, (a.SS+b.SS)%MOD);
}
void update(int idx, int l0, int r0, int p, ii v, int t) {
if(l0>p||r0<p) return;
if(l0==r0&&l0==p) {
if (t&1) st[idx].v=add(st[idx].v, v);
else st[idx].v=v; return;
}
int mid=(l0+r0)/2;
update(idx*2, l0, mid, p, v, t), update(idx*2+1, mid+1, r0, p, v, t);
st[idx].v=add(st[idx*2].v, st[idx*2+1].v);
}
ii get(int idx, int l0, int r0, int l, int r) {
if(l0>r||r0<l) return ii(0, 0);
if(l<=l0&&r0<=r) return st[idx].v;
int mid=(l0+r0)/2;
return add(get(idx*2, l0, mid, l, r), get(idx*2+1, mid+1, r0, l, r));
}
void upd(int p, ii v, int t) {update(1, 1, n, p, v, t);}
ii qry(int r) {if(!r) return ii(0, 1);return max(ii(0, 1), get(1, 1, n, 1, r));}
vector<int> b;
int a[N];
int mul(int a, int b) {return (1LL*a*b)%MOD;}
int pw(int a, int b) {
if(!b) return 1;
int res=pw(a, b/2); res=mul(res, res);
if(b&1) res=mul(res, a); return res;
}
signed main() {
//freopen("sapso.inp", "r", stdin);
//freopen("sapso.out", "w", stdout);
//fastIO;
scanf("%d", &n); ii tmp;
for(int i=n+1;i<=2*n;a[2*n-i+1]=a[i], b.pb(a[i++])) scanf("%d", &a[i]);
sort(all(b)), b.resize(unique(all(b))-b.begin());
for(int i=1;i<=2*n;i++) {
a[i]=lb(all(b), a[i])-b.begin()+1;
tmp=qry(a[i]-1);
upd(a[i], ii(tmp.FF+1, tmp.SS), 1);
}
tmp=qry(sz(b));
if(tmp.FF==n) printf("%d 1", n);
else printf("%d %d", tmp.FF, mul(tmp.SS, pw(2, n-tmp.FF-1)));
return 0;
}
/* stuff you should look for
- int overflow, array bounds
- special cases (n=1?)
- do smth instead of do nothing and stay organized
- WRITE STUFF DOWN
- DONT JUST STICK ON ONE APPROACH
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |