-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuva481.cpp
107 lines (74 loc) · 1.38 KB
/
uva481.cpp
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
93
94
95
96
97
98
99
100
101
#include <cstdio>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <list>
#include <stack>
using namespace std;
void lis(vector<int> v)
{
int index;
//int len;
vector<int>::iterator low;
vector<int> tailTable;
tailTable.push_back(v[0]);
vector<int> parent;
parent.resize(v.size());
parent[0] = -1;
vector<int> indices;
indices.push_back(0);
for(int i = 1; i < v.size(); i++)
{
if(v[i] < tailTable[0])
{
tailTable[0] = v[i];
indices[0] = i;
parent[i] = -1;
}
else if(v[i] > tailTable[tailTable.size() - 1])
{
parent[i] = indices[indices.size() - 1];
tailTable.push_back(v[i]);
indices.push_back(i);
}
else
{
low = lower_bound(tailTable.begin(), tailTable.end(), v[i]);
index = low - tailTable.begin(); //e ceil direct aici
cout << index << " ";
parent[i] = indices[index - 1];
tailTable[index] = v[i];
indices[index] = i;
}
cout << tailTable.size() << endl;
}
cout << endl;
stack<int> st;
printf("%d\n", tailTable.size());
printf("-\n");
index = indices[indices.size() - 1];
while(index != -1)
{
st.push(v[index]);
index = parent[index];
}
while(!st.empty())
{
printf("%d\n", st.top());
st.pop();
}
}
int main()
{
vector<int> v;
int n;
while(scanf("%d", &n) != EOF)
{
v.push_back(n);
}
lis(v);
v.clear();
return 0;
}