Pagini recente » Cod sursa (job #2530788) | Cod sursa (job #513286) | Cod sursa (job #2288602) | Cod sursa (job #2107458) | Cod sursa (job #2734202)
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
#define debug(v,n) for (int i = 1; i <= (n); ++i) cout << v[i] << " ";
#define next cout << '\n'
#define LSB(a) ((-a) & a)
using namespace std;
const int N = 100005;
int n, AIB[N];
int v[N], idx[N];
bool cmp(int a, int b) {
if(v[a] == v[b])
return a > b;
return v[a] < v[b];
}
int check(int pos) {
int mx = 0;
while(pos > 0) {
//cout << pos - LSB(pos) + 1 << " " << pos << " " << AIB[pos]<< '\n';
mx = max(AIB[pos], mx);
pos -= LSB(pos);
}
return mx;
}
void update(int pos, int x) {
while(pos <= n) {
//cout << pos - LSB(pos) + 1 << " " << pos << '\n';
AIB[pos] = max(AIB[pos], x);
pos += LSB(pos);
}
}
int main() {
//ifstream fin("date.in.txt");
ifstream fin("scmax.in");
ofstream fout("scmax.out");
fin >> n;
vector<int> pos;
for (int i = 1; i <= n; ++i) {
fin >> v[i];
pos.push_back(i);
}
sort(pos.begin(), pos.end(), cmp);
for (int x : pos) {
update(x, check(x) + 1);
/*for (int i = 1; i <= n; ++i)
cout << AIB[i] << " ";
cout << '\n';
cout << '\n';
*/
}
fout << check(n);
return 0;
}