1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
| #include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9+9;
const int MAXN = 210000;
int n;
int a[MAXN];
void init(){
scanf("%d",&n);
for(int i = 1;i<=n;i++)
scanf("%d",&a[i]);
}
namespace Solve1{
int f[MAXN],t[MAXN],now,MAXANS;
vector<int> v[MAXN];
vector<ll> sum[MAXN];ll g[MAXN],tot[MAXN];
void output(int n,int *ff,ll *gg){
for(int i = 1;i<=n;i++)ff[i] = f[i],gg[i] = g[i];
}
void solve(){
a[0] = 0,f[0] = 0,g[0] = 1,t[0] = 0;
v[0].push_back(0),sum[0].push_back(1),tot[0] = 1;
now = 0;
for(int i = 1;i<=n;i++){
int tmp = lower_bound(t,t+now+1,a[i]) - t;
if(tmp == now+1) ++now;
f[i] = tmp,t[tmp] = a[i];
int w = upper_bound(v[f[i]-1].begin(),v[f[i]-1].end(),a[i],greater<int>()) - v[f[i]-1].begin();
ll ans = w == 0?0:sum[f[i]-1][w-1];
ans = (tot[f[i]-1] - ans)%mod;
g[i] = ans < 0?ans+mod:ans;
v[f[i]].push_back(a[i]);
tot[f[i]] = (tot[f[i]] + g[i])%mod;
sum[f[i]].push_back(tot[f[i]]);
MAXANS = max(MAXANS,f[i]);
}
}
}
namespace Solve2{
int f[MAXN],t[MAXN],now,MAXANS;
vector<int> v[MAXN];
vector<ll> sum[MAXN];ll g[MAXN],tot[MAXN];
void output(int n,int *ff,ll *gg){
for(int i = 1;i<=n;i++)ff[i] = f[i],gg[i] = g[i];
}
void solve(){
a[n+1] = 1e9,f[n+1] = 0,g[n+1] = 1,t[0] = 1e9;
v[0].push_back(1e9),sum[0].push_back(1),tot[0] = 1;
now = 0;
for(int i = n;i>=1;i--){// 这里相对上面有更改
int tmp = lower_bound(t,t+now+1,a[i],greater<int>()) - t;//这里相对上面有更改
if(tmp == now+1) ++now;
f[i] = tmp,t[tmp] = a[i];
int w = upper_bound(v[f[i]-1].begin(),v[f[i]-1].end(),a[i]) - v[f[i]-1].begin();//这里相对上面有更改
ll ans = w == 0?0:sum[f[i]-1][w-1];
ans = (tot[f[i]-1] - ans)%mod;
g[i] = ans < 0?ans+mod:ans;
v[f[i]].push_back(a[i]);
tot[f[i]] = (tot[f[i]] + g[i])%mod;
sum[f[i]].push_back(tot[f[i]]);
MAXANS = max(MAXANS,f[i]);
}
}
}
int F1[MAXN],F2[MAXN];ll G1[MAXN],G2[MAXN];
void solve(){
Solve1::solve(),Solve1::output(n,F1,G1);
Solve2::solve(),Solve2::output(n,F2,G2);
int maxans = Solve1::MAXANS;ll totans = 0;
for(int i = 1;i<=n;i++){
if(F1[i] == maxans) totans+=G1[i];
totans %= mod;
}
for(int i = 1;i<=n;i++){
if(F1[i] + F2[i] - 1 < maxans) printf("1");
else if(G1[i] * G2[i] % mod == totans) printf("3");
else printf("2");
}
printf("\n");
}
int main(){
init();
solve();
return 0;
}
|