Cod sursa(job #2916242)

Utilizator matwudemagogul matwu Data 28 iulie 2022 16:09:57
Problema Subsir crescator maximal Scor 5
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.96 kb
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define EFC cin.tie(nullptr)->ios_base::sync_with_stdio(false)
int d1[5] = { 0, -1, 0, 1, 0 };
int d2[5] = { 0, 0, 1, 0, -1 };
const int mod = 666013;
const int INF = 100000000;
int d11[9] = { 0 , -1, -1, 0, 1, 1, 1, 0, -1 };
int d22[9] = { 0, 0, 1, 1, 1, 0, -1, -1, -1 };
int est[3] = { 0, -1, 0 };
int est1[3] = { 0, 0, 1 };
ifstream fin("scmax.in");
ofstream fout("scmax.out");


//----------------------------------

ll n, v[100001], d[100001], nr, maxim, ind;
vector<vector<int>> lene(100001);
int main() {

	fin >> n;
	for (int i = 1; i <= n; i++) {
		fin >> v[i];
	}

	for (int i = 1; i <= n; i++) {

		int l = 1, r = nr;
		while (l <= r) {
			int m = (l + r) / 2;
			if (d[m] < v[i]) {
				r = m - 1;
			}
			else {
				l = m + 1;
			}
		}
		if (l > nr) {
			d[++nr] = v[i];
		}
		else {
			d[l] = v[i];
		}
	}

	fout << nr;
}