Cod sursa(job #808672)

Utilizator ahmed.abdraboahmed.abdrabo ahmed.abdrabo Data 7 noiembrie 2012 08:52:11
Problema Subsir crescator maximal Scor 35
Compilator cpp Status done
Runda Arhiva educationala Marime 0.94 kb
#include <cstdio>
#include <algorithm>
using namespace std;

inline int next_int() {
	int n = 0;
	char c = getchar_unlocked();
	while (!('0' <= c && c <= '9')) {
		c = getchar_unlocked();
	}
	while ('0' <= c && c <= '9') {
		n = n * 10 + c - '0';
		c = getchar_unlocked();
	}
	return n;
}

const int MAX = 100001;
int N, A[MAX], BIT[MAX], LIS[MAX];
pair<int, int> S[MAX];

int get(int index) {
	int ans = 0;
	while (index > 0) {
		ans = max(ans, BIT[index]);
		index -= index & -index;
	}
	return ans;
}

void set(int index, int value) {
	while (index < MAX) {
		BIT[index] = max(value, BIT[index]);
		index += index & -index;
	}
}

int main() {
	freopen("scmax.in", "r", stdin);
	freopen("scmax.out", "w", stdout);
	N = next_int();
	for (int i = 1; i <= N; i++) {
		A[i] = next_int();
		S[i] = make_pair(A[i], -i);
	}
	sort(S + 1, S + N + 1);
	for (int i = 1; i <= N; i++) {
		set(-S[i].second, get(-S[i].second) + 1);
	}
	printf("%d ", get(N));
	return 0;
}