# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
448611 |
2021-07-31T07:32:41 Z |
Habitus |
Zoltan (COCI16_zoltan) |
C++14 |
|
326 ms |
15876 KB |
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dec(x, y) fixed << setprecision((y)) << (x)
#define xx first
#define yy second
#define srt(v) sort((v).begin(), (v).end())
#define srtr(v) sort((v).rbegin(), (v).rend())
#define pb push_back
#define popb pop_back
#define sz(a) (int)(a).size()
#define len(a) (int)(a).length()
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll mod=(ll)1e9+7LL;
int n, a[200010];
pii b[200010], lis[200010], lds[200010];
pair<int, ll> st[800010];
void build(int node, int tl, int tr) {
if(tl==tr) {st[node].xx=0; st[node].yy=1LL; return;}
int mid=(tl+tr)/2;
build(2*node, tl, mid);
build(2*node+1, mid+1, tr);
st[node].xx=0;
st[node].yy=0LL;
}
void upd(int node, int tl, int tr, int poz, pii val) {
if(tl==tr) {
if(st[node].xx!=val.xx) {st[node].xx=val.xx; st[node].yy=(ll)val.yy; return;}
else {++st[node].yy; return;}
}
int mid=(tl+tr)/2;
if(poz<=mid) upd(2*node, tl, mid, poz, val);
else upd(2*node+1, mid+1, tr, poz, val);
st[node].xx=max(st[2*node].xx, st[2*node+1].xx);
st[node].yy=(st[2*node].xx==st[node].xx?st[2*node].yy:0LL)+(st[2*node+1].xx==st[node].xx?st[2*node+1].yy:0LL);
}
pair<int, ll> query(int node, int tl, int tr, int gl, int gr) {
if(tl>=gl && tr<=gr) return st[node];
int mid=(tl+tr)/2;
pair<int, ll> res1={0, 0}, res2={0, 0};
if(mid>=gl) res1=query(2*node, tl, mid, gl, gr);
if(mid+1<=gr) res2=query(2*node+1, mid+1, tr, gl, gr);
if(res1.xx>res2.xx) return res1;
else if(res2.xx>res1.xx) return res2;
else return {res1.xx, res1.yy+res2.yy};
}
ll step(int sta) {
if(sta==-1) return 1LL;
if(sta==0) return 1LL;
if(sta==1) return 2LL;
ll pola=step(sta/2);
pola*=pola; pola%=mod;
if(sta&1) {pola*=2LL; pola%=mod;}
return pola;
}
int main() {
ios;
cin >> n;
for(int i=0; i<n; ++i) {
cin >> b[i].xx;
b[i].yy=i;
}
sort(b, b+n);
int dokle=1;
a[b[0].yy]=1;
for(int i=1; i<n; ++i) {
a[b[i].yy]=(b[i-1].xx==b[i].xx?dokle:++dokle);
}
build(1, 1, dokle);
lis[n-1].xx=lis[n-1].yy=1;
upd(1, 1, dokle, a[n-1], {1, 1});
for(int i=n-2; i>=0; --i) {
if(a[i]==dokle) {
lis[i].xx=1; lis[i].yy=1;
}
else {
pair<int, ll> nes=query(1, 1, dokle, a[i]+1, dokle);
lis[i].xx=nes.xx+1; lis[i].yy=nes.yy;
}
upd(1, 1, dokle, a[i], lis[i]);
}
build(1, 1, dokle);
lds[n-1].xx=lds[n-1].yy=1;
upd(1, 1, dokle, a[n-1], {1, 1});
for(int i=n-2; i>=0; --i) {
if(a[i]==1) {
lds[i].xx=1; lds[i].yy=1;
}
else {
pair<int, ll> nes=query(1, 1, dokle, 1, a[i]-1);
lds[i].xx=nes.xx+1; lds[i].yy=nes.yy;
}
upd(1, 1, dokle, a[i], lds[i]);
}
int mx=0;
for(int i=0; i<n; ++i) {
mx=max(mx, lis[i].xx+lds[i].xx-1);
}
cout << mx << ' ';
ll uk=0LL;
ll stepen=step(n-mx-1);
for(int i=0; i<n; ++i) {
if(lis[i].xx+lds[i].xx-1!=mx) continue;
uk+=lis[i].yy%mod*lds[i].yy%mod*stepen*(i==0 && mx!=n ?2LL:1LL)%mod;
}
cout << uk;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
332 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 |
328 KB |
Output isn't correct |
11 |
Incorrect |
176 ms |
14000 KB |
Output isn't correct |
12 |
Incorrect |
150 ms |
13296 KB |
Output isn't correct |
13 |
Incorrect |
143 ms |
9028 KB |
Output isn't correct |
14 |
Incorrect |
185 ms |
13592 KB |
Output isn't correct |
15 |
Incorrect |
249 ms |
14800 KB |
Output isn't correct |
16 |
Incorrect |
326 ms |
15876 KB |
Output isn't correct |
17 |
Incorrect |
236 ms |
15196 KB |
Output isn't correct |
18 |
Incorrect |
229 ms |
15188 KB |
Output isn't correct |
19 |
Incorrect |
241 ms |
15292 KB |
Output isn't correct |
20 |
Incorrect |
248 ms |
15188 KB |
Output isn't correct |