Pagini recente » Cod sursa (job #756730) | Cod sursa (job #2767201) | Cod sursa (job #1053203) | Cod sursa (job #2471235) | Cod sursa (job #2744262)
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
#define LSB(a) ((-a) & a)
using namespace std;
#ifdef LOCAL
#define read() ifstream fin("date.in.txt");
#else
#define read() ifstream fin("scmax.in"); ofstream fout("scmax.out");
#endif // LOCAL
const int N = 200005;
int n, AIB[N];
int v[N];
map<int,int> idx;
set<int> vals;
int last[N];
bool cmp(int a, int b) {
return v[a] < v[b];
}
void update(int pos, int act) {
int have = 1;
while(pos <= n * 2) {
if(last[pos] < act){
++AIB[pos];
have = max(AIB[pos], have);
last[pos] = act;
}
else if(AIB[pos] == have)
last[pos] = min(last[pos], act);
pos += LSB(pos);
}
}
int main() {
read();
fin >> n;
for (int i = 1; i <= n; ++i) {
fin >> v[i];
vals.insert(v[i]);
}
int p = 1;
for (int x : vals)
idx[x] = p++;
for (int i = 1; i <= n; ++i) {
update(idx[v[i]], v[i]);
/*for (int j = 1; j <= n * 2; ++j)
cout << AIB[j] << " ";
cout << '\n';
for (int j = 1; j <= n * 2; ++j)
cout << last[j] << " ";
cout << '\n';
cout << '\n';
*/
}
int mx = 0;
for (int i = 1; i <= n * 2; ++i)
mx = max(mx, AIB[i]);
#ifdef LOCAL
cout << mx << '\n';
#else
fout << mx << '\n';
#endif // LOCAL
return 0;
}