每次保存每个隧道的队尾列车标号,找到最接近上一个车尾的,将它顶掉。
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
int n;
cin >> n;
set<int> S;
S.insert(9999999);
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
auto it = S.upper_bound(x);
if (*it > x)
{
S.erase(*it);
S.insert(x);
}
else
{
S.insert(x);
}
}
cout << S.size() << endl;
return 0;
}