-
Notifications
You must be signed in to change notification settings - Fork 0
/
LIS
83 lines (75 loc) · 1.42 KB
/
LIS
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
//Code is tested on https://codeforces.com/contest/486/problem/E
#include<bits/stdc++.h>
using namespace std;
#define sz 100009
vector<int>v,ans;
int arr[sz],revarr[sz];
int li[sz],ld[sz],freq[sz];
void lis(int n)
{
v.clear();
v.push_back(-sz);
int k;
for(int i=1; i<=n; i++)
{
if(arr[i]>v[v.size()-1])
{
v.push_back(arr[i]);
li[i]=v.size()-1;
continue;
}
k=lower_bound(v.begin(),v.end(),arr[i])-v.begin();
li[i]=k;
v[k]=arr[i];
}
}
void lds(int n)
{
v.clear();
v.push_back(-sz);
int k;
for(int i=1; i<=n; i++)
{
if(revarr[i]>v[v.size()-1])
{
v.push_back(revarr[i]);
ld[i]=v.size()-1;
continue;
}
k=lower_bound(v.begin(),v.end(),revarr[i])-v.begin();
ld[i]=k;
v[k]=revarr[i];
}
}
int main()
{
int n,i,p;
scanf("%d",&n);
for(i=1; i<=n; i++)
{
scanf("%d",&arr[i]);
revarr[n-i+1]=-arr[i];
}
lis(n);
p=v.size()-1;
lds(n);
ans.clear();
for(i=1; i<=n; i++)
{
if(li[i]+ld[n-i+1]==p+1)
freq[li[i]]++;
}
for(i=1; i<=n; i++)
{
if(li[i]+ld[n-i+1]==p+1)
{
if(freq[li[i]]==1)
printf("3");
else
printf("2");
}
else
printf("1");
}
return 0;
}