-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path00497.cpp
More file actions
79 lines (77 loc) · 1.66 KB
/
00497.cpp
File metadata and controls
79 lines (77 loc) · 1.66 KB
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
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstdio>
using namespace std;
vector<int> in,last;
int getact(int l,int r,int key)
{
while(r>l)
{
int mid = (r+l)/2;
if(in[last[mid]]>=key)
r = mid;
else
l = mid+1;
}
return l;
}
int main()
{
char input[50];
int t;
cin>>t;
cin.getline(input,50);
cin.getline(input,50);
while(t--)
{
in.clear();
last.clear();
while(1)
{
cin.getline(input,50);
if(cin.eof())
break;
if(input[0]=='\0')
break;
int num= atoi(input);
in.push_back(num);
}
vector<int> pre(in.size(),-1);
for(int i=0;i<in.size();i++)
{
if(last.empty())
{
last.push_back(i);
pre[i] = -1;
}
else if(in[i]>in[last[last.size()-1]])
{
pre[i] = last[last.size()-1];
last.push_back(i);
}
else if(in[i]<in[last[0]])
{
pre[i] = -1;
last[0] = i;
}
else
{
int v=getact(0,last.size()-1,in[i]);
last[v] = i;
pre[i] = last[v-1];
}
}
printf("Max hits: %d\n",last.size());
vector<int> ans;
for(int i=last[last.size()-1];i>=0;i = pre[i])
{
ans.push_back(in[i]);
}
for(int i=ans.size()-1;i>=0;i--)
cout<<ans[i]<<endl;
if(t)
printf("\n");
}
return 0;
}