solution
stringlengths 11
983k
| difficulty
int64 0
21
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 102010;
int d[MAXN];
int dp[MAXN];
int tree[MAXN];
int N;
void update(int k, int v) {
while (k <= N) {
tree[k] = max(tree[k], v);
k += k & -k;
}
}
int read(int k) {
int ret = 0;
while (k) {
ret = max(ret, tree[k]);
k -= k & -k;
}
return ret;
}
int main() {
while (cin >> N) {
memset(dp, 0, sizeof(dp));
memset(tree, 0, sizeof(tree));
int ans = 0;
for (int i = 1; i <= N; ++i) {
scanf("%d", d + i);
dp[i] = read(d[i]) + 1;
update(d[i], dp[i]);
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int CeilIndex(int A[], int l, int r, int key) {
int m;
while (r - l > 1) {
m = l + (r - l) / 2;
(A[m] <= key ? l : r) = m;
}
return r;
}
int LongestIncreasingSubsequenceLength(int A[], int size) {
int *tailTable = new int[size];
int len;
memset(tailTable, 0, sizeof(tailTable[0]) * size);
tailTable[0] = A[0];
len = 1;
for (int i = 1; i < size; i++) {
if (A[i] < tailTable[0])
tailTable[0] = A[i];
else if (A[i] >= tailTable[len - 1])
tailTable[len++] = A[i];
else
tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i];
}
delete[] tailTable;
return len;
}
int main() {
int n, a[100009], c[100009];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
c[i] = 0;
}
int ans = 0;
ans = LongestIncreasingSubsequenceLength(a, n);
printf("%d\n", ans);
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int mini[100005], sz;
int main() {
int n;
cin >> n;
memset(mini, 127, sizeof(mini));
mini[0] = 0;
for (int i = 1; i <= n; ++i) {
int x, j = sz;
cin >> x;
for (; mini[j] > x; --j)
;
mini[j + 1] = min(mini[j + 1], x);
sz = max(sz, j + 1);
}
cout << sz;
return 0;
}
| 8 | CPP |
import sys; sys.setrecursionlimit(1000000)
def solve():
# 3 1 2 4
# 1 2 3 4
# 2 1 3 5 4
# 1 2 3 4 5
n, = rv()
a, = rl(1)
# 3 1 2 7 4 6 5
# [ , 1 , , , , ]
# [ , 1 , 2 , , , ]
# [ , 1 , 2 , 4, 5, ]
mem = [10000000] * (n + 1)
mem[0] = a[0]
for i in range(1, n):
left, right = 0, n - 1
while left < right:
mid = (left + right) // 2
if a[i] < mem[mid]: right = mid
else: left = mid + 1
mem[left] = a[i]
# for j in range(n):
# if a[i] < mem[j]:
# mem[j] = a[i]
# break
res = 0
# print(mem)
for i in range(1, n):
if mem[i] != 10000000: res = i
print(res + 1)
def rv(): return map(int, input().split())
def rl(n): return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int max_length = 0;
void add(vector<int> &T, int x) {
auto y = lower_bound(T.begin(), T.end(), x);
if (y == T.end()) {
T.push_back(x);
++max_length;
} else {
*y = x;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
vector<int> T;
int n;
cin >> n;
int x;
for (int i = 0; i < n; ++i) {
cin >> x;
add(T, x);
}
cout << max_length << '\n';
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
const int INF = 1000000000;
int n, a[MAXN], f[MAXN], c[MAXN], ans;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
f[0] = 0, c[0] = 0;
for (int i = 1; i <= n; i++) c[i] = INF;
for (int i = 1; i <= n; i++) {
f[i] = lower_bound(c, c + n + 1, a[i]) - c;
c[f[i]] = min(c[f[i]], a[i]);
}
for (int i = 1; i <= n; i++) ans = max(ans, f[i]);
printf("%d\n", ans);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int f[100100], n;
int get(int x) {
int res = 0;
for (int i = x; i; i -= i & -i) res = max(res, f[i]);
return res;
}
void update(int x, int val) {
for (int i = x; i <= n; i += i & -i) f[i] = max(f[i], val);
}
int main() {
int x, ans = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
int F = get(x) + 1;
ans = max(ans, F);
update(x, F);
}
cout << ans << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 2e5 + 10;
int n, temp;
vector<int> ans;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> temp;
int pos = lower_bound(ans.begin(), ans.end(), temp) - ans.begin();
if (pos == ans.size())
ans.push_back(temp);
else
ans[pos] = temp;
}
cout << ans.size() << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int LIS(vector<int> A) {
int N = A.size(), i;
set<int> s;
set<int>::iterator k;
for (i = 0; i < N; i++) {
if (s.insert(A[i]).second) {
k = s.find(A[i]);
k++;
if (k != s.end()) s.erase(k);
}
}
return s.size();
}
int n, aux;
vector<int> a;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &aux);
a.push_back(aux);
}
printf("%d\n", LIS(a));
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, sz, d[300001], i, x;
void update(int p) {
p /= 2;
while (p) {
d[p] = max(d[p * 2], d[p * 2 + 1]);
p /= 2;
}
}
int tree(int l, int r) {
int ans = -2147483647;
while (l <= r) {
if (l % 2 == 1 && ans < d[l]) ans = d[l];
if (r % 2 == 0 && ans < d[r]) ans = d[r];
l = (l + 1) / 2;
r = (r - 1) / 2;
}
return ans;
}
int main() {
sz = 1;
while (sz < 100000) {
sz *= 2;
}
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &x);
if (x == 1)
d[x + sz - 1] = 1;
else
d[x + sz - 1] = 1 + tree(sz, x + sz - 2);
update(x + sz - 1);
}
printf("%d", d[1]);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
const int INF = 1000000;
long long a[MAXN];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
vector<int> d;
d.resize(n + 1);
d[0] = -INF;
for (int i = 1; i <= n; ++i) d[i] = INF;
for (int i = 0; i < n; i++) {
int j = int(upper_bound(d.begin(), d.end(), a[i]) - d.begin());
if (d[j - 1] < a[i] && a[i] < d[j]) d[j] = a[i];
}
int ans;
for (int i = 1; i <= n; i++)
if (d[i] != INF) ans = i;
cout << ans;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n, sz, i, ans, j, a[200001], t[531172], op;
void upd(int x) {
for (j = x / 2; j >= 1; j /= 2) t[j] = max(t[j * 2], t[j * 2 + 1]);
}
long long finds(int l, int r) {
long long sum = -1;
while (l <= r) {
if (l % 2 == 1) sum = max(sum, t[l]);
if (r % 2 == 0) sum = max(sum, t[r]);
l++, r--, l /= 2, r /= 2;
}
return sum;
}
int main() {
cin >> n;
sz = 1;
while (sz < n) sz *= 2;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = 1; i <= n; i++) {
t[a[i] + sz - 1] = finds(sz, a[i] + sz - 1) + 1;
upd(a[i] + sz - 1);
}
cout << max(t[1], 1ll);
}
| 8 | CPP |
MXusl = int
MXuso = input
MXusL = map
MXusr = min
MXusI = print
n = MXusl(MXuso())
a = [1e6] * (n + 1)
s = 1
for x in MXusL(MXusl, MXuso().split()):
l = 0
r = s
while r-l > 1:
m = (l + r) >> 1
if a[m] < x:
l = m
else:
r = m
s += r == s
a[r] = MXusr(a[r], x)
MXusI(s - 1)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int N, i, ANS;
int A[100010];
int AIB[4 * 100010];
void update(int p, int v) {
for (; p <= N; p += (p & (-p))) AIB[p] = max(AIB[p], v);
}
int query(int p) {
int v = 0;
for (; p >= 1; p -= (p & (-p))) v = max(v, AIB[p]);
return v;
}
int main() {
cin >> N;
for (i = 1; i <= N; i++) {
cin >> A[i];
int l = query(A[i]);
l++;
ANS = max(ANS, l);
update(A[i], l);
}
cout << ANS << '\n';
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T mabs(const T &a) {
return a < 0 ? -a : a;
}
const int MaxLength = 100500;
int dyn[MaxLength];
int arr[MaxLength];
void run() {
int n;
scanf("%d", &n);
for (int i = (0), ei = (n); i < ei; i++) {
scanf("%d", &arr[i]);
}
vector<int> d(n + 1);
d[0] = -100500;
for (int i = 1; i <= n; ++i) d[i] = 100500;
for (int i = 0; i < n; i++) {
int j = upper_bound(d.begin(), d.end(), arr[i]) - d.begin();
if (d[j - 1] < arr[i] && arr[i] < d[j]) d[j] = arr[i];
}
int ans = 0;
for (int i = (0), ei = (n + 1); i < ei; i++) {
if (d[i] != 100500) ans = i;
}
cout << ans << endl;
}
int main() {
run();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> arr(1e5 + 5);
vector<int> lel(1e5 + 5);
struct cmp {
bool operator()(int i, int j) const { return arr[i] < arr[j]; }
};
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
arr[n] = 1e9;
arr[n + 1] = -1e9;
fill(lel.begin(), lel.end(), n);
lel[0] = n + 1;
int res = 0;
for (int i = 0; i < n; i++) {
int len = lower_bound(lel.begin(), lel.end(), i, cmp()) - lel.begin();
lel[len] = i;
res = max(res, len);
}
cout << res;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int p[100100], f[100100];
int main() {
int res, N, t;
res = 1;
scanf("%d", &N);
for (int i = 0; i < N; i++) scanf("%d", p + i);
memset(f, 0x3f3f3f3f, sizeof(f));
for (int i = 0; i < N; i++) {
t = lower_bound(f, f + N, p[i]) - f;
res = max(res, t + 1);
f[t] = p[i];
}
printf("%d\n", res);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int inf = 1e9 - 1;
int dp[maxn], a[maxn], n, m = 0;
int main() {
cin >> n;
for (int i = 1; i <= maxn; i++) dp[i] = inf;
dp[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
int j = lower_bound(dp, dp + n, a[i]) - dp - 1;
dp[j + 1] = min(dp[j + 1], a[i]);
m = max(j + 1, m);
}
cout << m;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
template <class T>
T MIN(const T& a, const T& b) {
return a < b ? a : b;
}
template <class T>
T MAX(const T& a, const T& b) {
return a > b ? a : b;
}
template <class T>
void MIN_UPDATE(T& a, const T& b) {
if (a > b) a = b;
}
template <class T>
void MAX_UPDATE(T& a, const T& b) {
if (a < b) a = b;
}
const int inf = 99999999;
vector<int> lis_fast(const vector<int>& a) {
const int n = a.size();
vector<int> A(n, inf);
vector<int> id(n);
for (int i = 0; i < n; ++i) {
id[i] = distance(A.begin(), lower_bound(A.begin(), A.end(), a[i]));
A[id[i]] = a[i];
}
int m = *max_element(id.begin(), id.end());
vector<int> b(m + 1);
for (int i = n - 1; i >= 0; --i)
if (id[i] == m) b[m--] = a[i];
return b;
}
int main() {
std::ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a;
for (int i = 0; i < (int)n; ++i) {
int value;
cin >> value;
a.push_back(value);
}
cout << lis_fast(a).size() << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<int> a, b;
int LIS() {
int u, v;
b.push_back(0);
for (int i = 1; i < a.size(); i++) {
if (a[b.back()] < a[i]) {
b.push_back(i);
continue;
}
for (u = 0, v = b.size() - 1; u < v;) {
int c = (u + v) / 2;
if (a[b[c]] < a[i])
u = c + 1;
else
v = c;
}
if (a[i] < a[b[u]]) b[u] = i;
}
return b.size();
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
int t;
cin >> t;
a.push_back(t);
}
cout << LIS() << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
const int maxn = 100005;
int arr[maxn];
using namespace std;
int main() {
int n;
scanf("%d", &n);
int top = 1;
int ans;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
int idx = 1;
int lo = 1;
int hi = top - 1;
int mi;
if (top == 1) {
arr[1] = x;
ans = 1;
top++;
} else if (x < arr[1]) {
arr[1] = x;
} else if (x > arr[top - 1]) {
arr[top++] = x;
ans = max(ans, top - 1);
} else {
while (lo <= hi) {
mi = (lo + hi) / 2;
if (arr[mi] < x && (mi == top || arr[mi + 1] > x)) break;
if (arr[mi] < x)
lo = mi + 1;
else
hi = mi - 1;
}
arr[mi + 1] = x;
}
}
printf("%d\n", ans);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int bit[(int)1e5 + 100];
void add(int pos, int val) {
for (int i = pos; i > 0; i -= (i & -i)) bit[i] = max(bit[i], val);
}
int get(int pos) {
int soma = 0;
for (int i = pos; i < (int)1e5 + 100; i += (i & -i)) soma = max(soma, bit[i]);
return soma;
}
int main() {
int n;
int bs = 0;
scanf("%d", &n);
vector<int> val;
for (int i = 0; i < n; i++) {
int va;
scanf("%d", &va);
val.push_back(va);
}
for (int j = n - 1; j >= 0; j--) {
int now = get(val[j]) + 1;
bs = max(bs, now);
add(val[j], now);
}
printf("%d\n", bs);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int n;
cin >> n;
int a[100005];
for (int i = 0; i < n; i++) cin >> a[i];
int ans[100004];
int j = 0;
ans[0] = a[0];
for (int i = 1; i < n; i++) {
if (a[i] > ans[j]) {
ans[++j] = a[i];
} else {
int lo = 0, hi = j, res = 0;
while (hi >= lo) {
int mid = (hi + lo) / 2;
if (ans[mid] >= a[i]) {
res = mid;
hi = mid - 1;
} else
lo = mid + 1;
}
ans[res] = a[i];
}
}
cout << j + 1 << "\n";
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000009, maxn = 400000;
const long long INF = 1000000000ll * 1000000000ll;
int rmq[maxn << 2];
int n;
void insert(int i, int w) {
int id = 1, l = 0, r = n, m;
while (l < r) {
m = (l + r) / 2;
id *= 2;
if (i <= m)
r = m;
else
l = m + 1, ++id;
}
rmq[id] = w;
id /= 2;
while (id >= 1) {
rmq[id] = max(rmq[id * 2], rmq[id * 2 + 1]);
id /= 2;
}
}
int maxf(int i, int l, int r, int nl, int nr) {
if (r < nl || nr < l || l > r) return 0;
if (nl <= l && r <= nr) return rmq[i];
int m = (l + r) / 2;
return max(maxf(i * 2, l, m, nl, nr), maxf(i * 2 + 1, m + 1, r, nl, nr));
}
int L, d, af;
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
scanf("%d", &af);
int tmp = maxf(1, 0, n, 0, af - 1) + 1;
insert(af, tmp);
}
cout << rmq[1] << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 * 1000;
int v[maxn + 10];
int dp[maxn + 10];
int main() {
int n, ans = 1;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
for (int i = 1; i <= n; i++) {
int tmp = (upper_bound(dp, dp + ans, v[i]) - dp);
if (tmp >= ans) {
ans++;
}
dp[tmp] = v[i];
}
cout << endl << ans - 1;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<int> dp;
void ok(int curr, int val) {
curr /= 2;
while (curr > 0) {
dp[curr] = max(dp[2 * curr], dp[2 * curr + 1]);
curr /= 2;
}
}
int query(int a, int b, int curr, int l, int r) {
if (a > r || b < l) {
return 0;
}
if (a <= l && b >= r) {
return dp[curr];
}
int h = (l + r) / 2;
return max(query(a, b, 2 * curr, l, h), query(a, b, 2 * curr + 1, h + 1, r));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, a;
cin >> n;
int t = pow(2, ceil(double(log2(n))));
dp.resize(2 * t, 0);
for (int i = 0; i < n; i += 1) {
cin >> a;
if (a > 1) {
dp[t + a - 1] = 1 + query(t, t + a - 2, 1, t, 2 * t - 1);
ok(t + a - 1, dp[t + a - 1]);
} else {
dp[t + a - 1] = 1;
}
}
cout << dp[1];
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, a[200000], f[200000], ans;
int c[200000];
void modify(int x, int y) {
for (; x <= n; x += x & -x) c[x] = max(c[x], y);
}
int query(int x) {
int ret(0);
for (; x; x -= x & -x) ret = max(ret, c[x]);
return ret;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= (n); ++i) scanf("%d", &a[i]);
for (int i = 1; i <= (n); ++i) {
f[i] = query(a[i]) + 1;
modify(a[i], f[i]);
ans = max(ans, f[i]);
}
printf("%d\n", ans);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long n, m, i, j, a, b, z, q, k, len = 0;
cin >> n;
long A[n];
vector<long> tail(n + 1, 0);
for (i = 0; i < n; i++) cin >> A[i];
tail[len++] = A[0];
for (i = 1; i < n; i++) {
if (A[i] >= tail[len - 1])
tail[len++] = A[i];
else {
k = upper_bound(tail.begin(), tail.begin() + len, A[i]) - tail.begin();
tail[k] = A[i];
}
}
cout << len;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmax(T& a, const T& b) {
a = max(a, b);
}
template <class T>
void chmin(T& a, const T& b) {
a = min(a, b);
}
template <class T>
void uniq(T& c) {
sort(c.begin(), c.end());
c.erase(unique(c.begin(), c.end()), c.end());
}
template <class T>
string to_s(const T& a) {
ostringstream os;
os << a;
return os.str();
}
template <class T>
T to_T(const string& s) {
istringstream is(s);
T res;
is >> res;
return res;
}
template <typename T>
void print_container(ostream& os, const T& c) {
const char* _s = " ";
if (!c.empty()) {
__typeof__(c.begin()) last = --c.end();
for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it) {
os << *it;
if (it != last) cout << _s;
}
}
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& c) {
print_container(os, c);
return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& c) {
print_container(os, c);
return os;
}
template <typename T>
ostream& operator<<(ostream& os, const multiset<T>& c) {
print_container(os, c);
return os;
}
template <typename T>
ostream& operator<<(ostream& os, const deque<T>& c) {
print_container(os, c);
return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& c) {
print_container(os, c);
return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <class T>
void print(T a, int n, const string& deli = " ", int br = 1) {
for (int i = 0; i < n; ++i) {
cout << a[i];
if (i + 1 != n) cout << deli;
}
while (br--) cout << endl;
}
template <class T>
void print2d(T a, int w, int h, int width = -1, int br = 1) {
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (width != -1) cout.width(width);
cout << a[i][j] << ' ';
}
cout << endl;
}
while (br--) cout << endl;
}
template <class T>
void input(T& a, int n) {
for (int i = 0; i < n; ++i) cin >> a[i];
}
template <class T>
void input(T* a, int n) {
for (int i = 0; i < n; ++i) cin >> a[i];
}
void fix_pre(int n) {
cout.setf(ios::fixed, ios::floatfield);
cout.precision(10);
}
void fast_io() {
cin.tie(0);
ios::sync_with_stdio(false);
}
bool in_rect(int x, int y, int w, int h) {
return 0 <= x && x < w && 0 <= y && y < h;
}
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const double PI = acos(-1.0);
int main() {
fast_io();
int n;
static int a[((long long)(1e5))];
cin >> n;
input(a, n);
const int inf = ((long long)(1e9));
static int dp[((long long)(1e5)) + 100];
fill_n(dp, n + 30, inf);
for (int i = 0; i < (int)(n); ++i) {
int k = upper_bound(dp, dp + n, a[i]) - dp;
dp[k] = a[i];
}
int res = 0;
while (dp[res] < inf) ++res;
cout << res << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
long long powmod(long long a, long long b) {
long long res = 1;
if (a >= mod) a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a;
if (res >= mod) res %= mod;
a = a * a;
if (a >= mod) a %= mod;
}
return res;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long arr[100010], tree[1000100], n;
long long query(long long node, long long a, long long b, long long i,
long long j) {
if (a > b || i > b || j < a) return 0;
if (a >= i && b <= j) return tree[node];
return max(query(node * 2, a, (a + b) / 2, i, j),
query(node * 2 + 1, (a + b) / 2 + 1, b, i, j));
}
void update(long long node, long long a, long long b, long long i,
long long val) {
if (a > b || i < a || i > b) return;
if (a == b && a == i) {
tree[node] = val;
return;
}
long long mid = (a + b) / 2;
update(node * 2, a, mid, i, val);
update(node * 2 + 1, mid + 1, b, i, val);
tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long i, maxi, ans = 0;
cin >> n;
for (i = 0; i < n; i++) cin >> arr[i];
for (i = 0; i < n; i++) {
maxi = query(1, 0, n - 1, 1, arr[i] - 1);
ans = max(ans, maxi);
update(1, 0, n - 1, arr[i], maxi + 1);
}
cout << ans + 1;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> g(1);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x > g.back())
g.push_back(x);
else {
int p = lower_bound(g.begin(), g.end(), x) - g.begin();
g[p] = x;
}
}
cout << g.size() - 1 << '\n';
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, ans, q[200000], fen[200000];
int a[200000];
void up(int v, int val) {
while (v <= n) {
fen[v] = max(fen[v], val);
v = (v | (v + 1));
}
}
int get(int v) {
int ans = 0;
while (v > 0) {
ans = max(ans, fen[v]);
v = (v & (v + 1)) - 1;
}
return ans;
}
int main() {
cin >> n;
ans = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
q[i] = get(a[i]) + 1;
up(a[i], q[i]);
ans = max(ans, q[i]);
}
cout << ans << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
int seg[1000000];
int dp[100001];
vector<int> num;
int update(int node, int s, int e, int in, int val) {
if (s == e) return seg[node] = val;
int mid = (s + e) >> 1;
if (in <= mid)
return seg[node] = max(seg[node], update(2 * node, s, mid, in, val));
return seg[node] = max(seg[node], update(2 * node + 1, mid + 1, e, in, val));
}
int query(int node, int s, int e, int f, int t) {
if (s == e) return seg[node];
if (f <= s && t >= e) return seg[node];
int mid = (s + e) >> 1;
if (t <= mid) return query(2 * node, s, mid, f, t);
if (f > mid) return query(2 * node + 1, mid + 1, e, f, t);
return max(query(2 * node, s, mid, f, t),
query(2 * node + 1, mid + 1, e, f, t));
}
int main() {
int n;
cin >> n;
num.resize(n + 1);
for (int i = 1; i <= n; ++i) cin >> num[i];
for (int i = 1; i <= n; ++i) {
int res = query(1, 1, n, 1, num[i] - 1);
dp[i] = res + 1;
update(1, 1, n, num[i], dp[i]);
}
cout << query(1, 1, n, 1, n) << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6 + 5;
const long long INF = 1e18 + 7;
const long long MOD = 1e9 + 7;
int n, res, pre[MX], lay[MX];
long long t[MX];
int BS(int pocz, int konc, long long x) {
if (konc - pocz <= 5) {
for (int i = konc; i >= pocz; --i)
if (t[lay[i]] >= x) return i;
}
int sr = (pocz + konc) / 2;
if (t[lay[sr]] >= x)
return BS(sr, konc, x);
else
return BS(pocz, sr - 1, x);
}
int main() {
scanf("%d", &n);
for (int i = (1); i <= (n); ++i) {
cin >> t[i];
t[i] = (long long)1e18 - t[i];
}
lay[0] = 0;
t[0] = INF;
pre[0] = -1;
for (int i = (1); i <= (n); ++i) {
int pos = BS(0, res, t[i]);
pre[i] = lay[pos];
lay[pos + 1] = i;
res = max(res, pos + 1);
}
printf("%d\n", res);
vector<int> r;
int akt = lay[res];
while (akt != 0) {
r.push_back(akt);
akt = pre[akt];
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
int main() {
int n;
scanf("%d", &n);
int i;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[i] = 999999999;
}
int tot = 0;
for (i = 0; i < n; i++) {
int now = lower_bound(b, b + tot, a[i]) - b;
if (now == tot) tot++;
b[now] = min(b[now], a[i]);
}
cout << tot << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100000;
vector<int> T;
int main() {
int N;
scanf("%d", &N);
T.push_back(0);
for (int i = 1; i <= N; i++) {
int x;
scanf("%d", &x);
if (x > T.back()) {
T.push_back(x);
continue;
}
*lower_bound(T.begin(), T.end(), x) = x;
}
printf("%d\n", (int)T.size() - 1);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, a[100010], b[100010], ans = 0;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = 1; i <= n; ++i) {
int L = 1, R = ans, M;
while (L <= R) {
M = (L + R) >> 1;
if (a[i] < b[M])
R = M - 1;
else
L = M + 1;
}
b[L] = a[i];
if (L > ans) ans = L;
}
printf("%d\n", ans);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
cin >> N;
vector<long long> v;
for (int i = 1; i <= N; i++) {
long long tmp;
cin >> tmp;
int idx = lower_bound(v.begin(), v.end(), tmp) - v.begin();
if (idx == v.size()) {
v.push_back(tmp);
} else {
v[idx] = tmp;
}
}
cout << v.size() << '\n';
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int N;
int f[100010];
int a[100010];
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; ++i) scanf("%d", &a[i]);
for (int i = 0; i <= N; ++i) f[i] = (1 << 30);
f[0] = 0;
int Ans = 0;
for (int i = 1; i <= N; ++i) {
int p = upper_bound(f, f + 1 + N, a[i]) - f;
if (p > Ans) Ans = p;
if (f[p] > a[i]) f[p] = a[i];
}
cout << Ans << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1E6;
const int MAXN = 1E5;
int a[MAXN + 2];
int d[MAXN + 2];
int bs(int x) {
int l = 1;
int r = MAXN + 1;
while (l < r) {
int c = (l + r) / 2;
if (d[c] > x) {
r = c;
} else
l = c + 1;
}
return l;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= MAXN; i++) {
d[i] = INF;
}
int max_l = 0;
for (int i = 0; i < n; i++) {
int j = bs(a[i]);
d[j] = min(d[j], a[i]);
max_l = max(max_l, j);
}
printf("%d\n", max_l);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxN = 100 * 1024;
int N, K;
int a[maxN];
int lis[maxN];
int main() {
ios_base::sync_with_stdio(false);
cin >> N;
for (int i = (1); i < (N + 1); i++) cin >> a[i];
for (int i = (1); i < (N + 2); i++) lis[i] = oo;
for (int i = (1); i < (N + 1); i++) {
int len = upper_bound(lis + 1, lis + N + 1, a[i]) - lis;
lis[len] = min(lis[len], a[i]);
}
int best = lower_bound(lis + 1, lis + N + 2, oo) - lis - 1;
cout << best << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N(100010);
int n, t;
int s[N];
int find(int l, int r, int a) {
if (l == r) return l;
int mid = (l + r) / 2;
if (a <= s[mid]) return find(l, mid, a);
return find(mid + 1, r, a);
}
int main() {
cin >> n;
int ans = 0;
for (int i = int(1); i < int(n + 1); ++i) {
int a;
cin >> a;
int x = find(0, t, a);
if (x == t)
s[t++] = a;
else
s[x] = a;
ans = max(ans, t);
}
printf("%d\n", ans);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int Infinity = 1000000001;
long int Max, kq;
int n, A[200000], f[200000];
void Sort(int Left, int Right) {
int i = Left;
int j = Right;
int Mid = f[(Left + Right) / 2];
while (i <= j) {
while (f[i] < Mid) i++;
while (f[j] > Mid) j--;
if (i <= j) {
int tmp = f[i];
f[i] = f[j];
f[j] = tmp;
i++;
j--;
}
}
if (Left < j) Sort(Left, j);
if (i < Right) Sort(i, Right);
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> A[i];
for (int i = 1; i <= n; i++) f[i] = Infinity;
f[0] = -Infinity;
for (int i = 1; i <= n; i++) {
int Mid;
int Left = 1;
int Right = n;
while (Right > Left + 1) {
Mid = (Left + Right) / 2;
if (f[Mid - 1] >= A[i])
Right = Mid;
else
Left = Mid;
}
if (f[Right - 1] <= A[i])
if (f[Right] > A[i]) Max = Right;
if (f[Left - 1] <= A[i])
if (f[Left] > A[i]) Max = Left;
f[Max] = A[i];
if (Max > kq) kq = Max;
}
cout << kq;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int T[400020];
int arr[100005];
int query(int at, int L, int R, int l, int r) {
if (r < L || R < l) return 0;
if (l <= L && R <= r) return T[at];
int mid = (L + R) / 2;
int x = query(at * 2, L, mid, l, r);
int y = query(at * 2 + 1, mid + 1, R, l, r);
return max(x, y);
}
void update(int at, int L, int R, int pos, int u) {
if (L == R) {
T[at] = u;
return;
}
int mid = (L + R) / 2;
if (pos <= mid) {
update(at * 2, L, mid, pos, u);
} else {
update(at * 2 + 1, mid + 1, R, pos, u);
}
T[at] = max(T[at * 2], T[at * 2 + 1]);
}
void build(int at, int L, int R) {
T[at] = 0;
if (L == R) {
T[at] = 0;
return;
}
int mid = (L + R) / 2;
build(at * 2, L, mid);
build(at * 2 + 1, mid + 1, R);
T[at] = max(T[at * 2], T[at * 2 + 1]);
}
bool comp(const pair<int, int> &a, const pair<int, int> &b) {
if (a.first == b.first) {
return a.second > b.second;
}
return a.first < b.first;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
long long a[n + 1];
map<long long, int> mp;
vector<pair<int, int> > vec;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mp[a[i]] = i;
vec.push_back({a[i], i});
}
sort(vec.begin(), vec.end(), comp);
build(1, 1, n);
for (int i = 0; i < n; i++) {
int u = query(1, 1, n, 1, vec[i].second) + 1;
update(1, 1, n, vec[i].second, u);
}
int mx = 1;
for (int i = 1; i <= n; i++) {
mx = max(mx, T[i]);
}
cout << mx;
}
| 8 | CPP |
#include <bits/stdc++.h>
const int N = 100005;
int subseq(int n, const int *a) {
static int b[N + 1];
int i, l, r, m, ret = 0;
for (i = 0; i < n; b[l] = i++, ret += (l > ret)) {
for (m = ((l = 1) + (r = ret)) >> 1; l <= r; m = (l + r) >> 1) {
if (((a[b[m]]) < (a[i]))) {
l = m + 1;
} else {
r = m - 1;
}
}
}
return ret;
}
int n, a[N];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
}
printf("%d\n", subseq(n, a));
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int p[100100], buf[100100];
int main() {
int ans = 1, n;
memset(buf, 0x3f3f, sizeof(buf));
cin >> n;
for (int i = 0; i < n; i++) scanf("%d", p + i);
for (int i = 0; i < n; i++) {
int j = lower_bound(buf, buf + n, p[i]) - buf;
buf[j] = p[i];
ans = max(ans, j + 1);
}
cout << ans << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int ans, a[100010], c[100010], n, t;
void add(int pos, int x) {
while (pos <= n) c[pos] = max(c[pos], x), pos += pos & -pos;
}
int ask(int pos, int res = 0) {
while (pos) res = max(res, c[pos]), pos -= pos & -pos;
return res;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]), t = ask(a[i] - 1) + 1, ans = max(ans, t), add(a[i], t);
printf("%d", ans);
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int CeilIndex(std::vector<int> &v, int l, int r, int key) {
while (r - l > 1) {
int m = l + (r - l) / 2;
if (v[m] >= key)
r = m;
else
l = m;
}
return r;
}
int LIS(std::vector<int> &v) {
if (v.size() == 0) return 0;
vector<int> tail(v.size(), 0);
int length = 1;
tail[0] = v[0];
for (size_t i = 1; i < v.size(); i++) {
if (v[i] < tail[0])
tail[0] = v[i];
else if (v[i] > tail[length - 1])
tail[length++] = v[i];
else
tail[CeilIndex(tail, -1, length - 1, v[i])] = v[i];
}
return length;
}
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
cout << LIS(v);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 111111;
int n;
int top;
int a[N];
int main() {
scanf("%d", &n);
top = 0;
for (int i = 0; i != n + 1; i++) a[i] = N;
for (int i = 0; i != n; i++) {
int x;
scanf("%d", &x);
int w = upper_bound(a + 1, a + n, x) - a;
top = max(top, w);
a[w] = x;
}
printf("%d\n", top);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int a[N], aib[N];
int n;
void update(int i, int val) {
for (; i < N; i += ((i) & (-i))) aib[i] = max(aib[i], val);
}
int query(int i) {
int ret = 0;
for (; i > 0; i -= ((i) & (-i))) ret = max(ret, aib[i]);
return ret;
}
int main() {
int i, sol = 0, s;
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
for (i = 1; i <= n; i++) {
s = query(a[i] - 1);
update(a[i], s + 1);
sol = max(sol, s);
}
printf("%d", sol + 1);
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void debug(T1 e) {
cout << e << endl;
}
template <class T1, class T2>
void debug(T1 e1, T2 e2) {
cout << e1 << "\t" << e2 << endl;
}
template <class T1, class T2, class T3>
void debug(T1 e1, T2 e2, T3 e3) {
cout << e1 << "\t" << e2 << "\t" << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void debug(T1 e1, T2 e2, T3 e3, T4 e4) {
cout << e1 << "\t" << e2 << "\t" << e3 << "\t" << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void debug(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
cout << e1 << "\t" << e2 << "\t" << e3 << "\t" << e4 << "\t" << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void debug(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
cout << e1 << "\t" << e2 << "\t" << e3 << "\t" << e4 << "\t" << e5 << "\t"
<< e6 << endl;
}
template <class T>
void debug(vector<vector<T> > e, int row, int col) {
int i, j;
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) cout << e[i][j] << " ";
cout << endl;
}
cout << endl;
}
template <class T>
void debug(vector<basic_string<T> > e, int row, int col) {
int i, j;
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) cout << e[i][j];
cout << endl;
}
cout << endl;
}
template <class T>
void debug(T e[110][110], int row, int col) {
int i, j;
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) cout << e[i][j] << " ";
cout << endl;
}
}
template <class T>
string toString(T n) {
ostringstream oss;
oss << n;
oss.flush();
return oss.str();
}
int toInt(string s) {
int r = 0;
istringstream sin(s);
sin >> r;
return r;
}
bool isVowel(char ch) {
ch = tolower(ch);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
return true;
return false;
}
bool isUpper(char c) { return c >= 'A' && c <= 'Z'; }
bool isLower(char c) { return c >= 'a' && c <= 'z'; }
int heap[4 * 100010];
void update(int in, int st, int end, int x, int val) {
if (st > x || end < x) return;
if (st == end) {
heap[in] = val;
return;
}
int mid = (st + end) / 2;
update(2 * in, st, mid, x, val);
update(2 * in + 1, mid + 1, end, x, val);
heap[in] = max(heap[2 * in], heap[2 * in + 1]);
return;
}
int query(int in, int st, int end, int x, int y) {
if (st > end) return 0;
if (st > y || end < x) return 0;
if (st >= x && end <= y) return heap[in];
int mid = (st + end) / 2;
int ret = query(2 * in, st, mid, x, y);
ret = max(ret, query(2 * in + 1, mid + 1, end, x, y));
return ret;
}
int main() {
int n;
while (cin >> n) {
memset(heap, 0, sizeof(heap));
int tem;
int i;
for (i = 1; i <= n; i++) {
cin >> tem;
update(1, 1, n, tem, query(1, 1, n, 1, tem - 1) + 1);
}
cout << heap[1] << endl;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int c[n + 5];
int a[n];
int k, m = 1;
cin >> a[0];
k = a[0];
c[0] = 0;
c[1] = k;
for (int i = 1; i < n; i++) {
cin >> a[i];
k = lower_bound(c, c + m + 1, a[i]) - c;
m = max(k, m);
c[k] = a[i];
}
cout << m;
return 0;
}
| 8 | CPP |
n = int(input())
num_list = list(map(int, input().split()))
# def lower_bound(min_lis, x):
# #goal return the position of the first element >= x
# left = 0
# right = len(min_lis) - 1
# res = -1
# while left <= right:
# mid = (left + right) // 2
# if min_lis[mid] < x:
# left = mid + 1
# else:
# res = mid
# right = mid - 1
# return res
import bisect
def LongestIncreasingSubsequence(a, n):
min_lis = []
#lis = [0 for i in range(n)]
for i in range(n):
pos = bisect.bisect_left(min_lis, a[i])
if pos == len(min_lis):
#lis[i] = len(min_lis) + 1
min_lis.append(a[i])
else:
#lis[i] = pos + 1
min_lis[pos] = a[i]
#print(*min_lis)
return (len(min_lis))
print(LongestIncreasingSubsequence(num_list, n))
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000 + 20;
int fen[MAX_N];
int n, ans;
int get(int x) {
int res = 0;
for (; x > 0; x -= (x) & (-x)) res = max(res, fen[x]);
return res;
}
void upd(int x, int val) {
for (; x < n; x += (x) & (-x)) fen[x] = max(fen[x], val);
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
int len = get(x - 1) + 1;
ans = max(ans, len);
upd(x, len);
}
cout << ans << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int(n);
scanf("%d", &(n));
int((a)[(n)]);
for (int i = 0; i < (n); i++) scanf("%d", &((a)[i]));
vector<int> lop;
int ci;
for (int(i) = 0; (i) < (n); (i)++) {
ci = upper_bound(lop.begin(), lop.end(), a[i]) - lop.begin();
if (ci >= int((lop).size()))
lop.push_back(a[i]);
else
lop[ci] = a[i];
}
cout << int((lop).size());
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1000007];
vector<int> v;
void f(int x) {
int l = 0;
int r = v.size() - 1;
if (v.size() == 0) {
v.push_back(x);
return;
}
if (x > v[r]) {
v.push_back(x);
return;
}
int mid;
while (r - l > 1) {
mid = (r + l) / 2;
if (v[mid] < x)
l = mid;
else
r = mid;
}
if (v[l] < x) l++;
v[l] = x;
}
void input();
void solve();
int main() {
input();
solve();
return 0;
}
void input() {
v.clear();
scanf("%d", &n);
int i;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
f(a[i]);
}
}
void solve() { printf("%d\n", v.size()); }
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int N = 1e5 + 10;
int a[N], q[N];
int main() {
int n, i;
scanf("%d", &n);
for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
int r = 0;
q[r++] = a[1];
for (i = 2; i <= n; ++i) {
int whe = lower_bound(q, q + r, a[i]) - q;
if (whe == r)
q[r++] = a[i];
else
q[whe] = a[i];
}
printf("%d\n", r);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000 + 10;
int n;
int a[MAX];
int sum[MAX];
void add(int a, int b) {
for (; a < MAX; a += a & (-a)) sum[a] = max(sum[a], b);
}
int ask(int a) {
int ans = 0;
for (; a; a -= a & (-a)) ans = max(ans, sum[a]);
return ans;
}
int main() {
int i;
scanf("%d", &n);
int ans = 0;
for ((i) = (1); (i) <= (n); ++(i)) {
scanf("%d", &a[i]);
int f = ask(a[i]) + 1;
ans = max(ans, f);
add(a[i], f);
}
printf("%d\n", ans);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const int N = 100005;
int f[N], n;
int low(int i) { return i & (-i); }
void up(int i, int j) {
while (i <= n) {
f[i] = max(f[i], j);
i += low(i);
}
}
int ask(int i) {
int ret = 0;
while (i > 0) {
ret = max(ret, f[i]);
i -= low(i);
}
return ret;
}
int main() {
scanf("%d", &n);
int ans = 0;
for (int i = 0; i < n; ++i) {
int x;
scanf("%d", &x);
int t = ask(x - 1) + 1;
ans = max(ans, t);
up(x, t);
}
cout << ans << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
int ar[100005];
vector<int> A;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) cin >> ar[i];
for (int i = 0; i < n; i++) {
if (i == 0)
A.push_back(ar[i]);
else if (ar[i] < A[0])
A[0] = ar[i];
else if (ar[i] > A.back())
A.push_back(ar[i]);
else
A[lower_bound(A.begin(), A.end(), ar[i]) - A.begin()] = ar[i];
}
cout << A.size() << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int lis(vector<int> const& a) {
int n = a.size();
const int INF = 1e9;
vector<int> d;
d.push_back(a[0]);
for (int i = 1; i < n; i++) {
if (a[i] > d[d.size() - 1])
d.push_back(a[i]);
else {
int idx = lower_bound(d.begin(), d.end(), a[i]) - d.begin();
if (idx == n) continue;
d[idx] = a[i];
}
}
return d.size();
}
int n, no;
vector<int> vi;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &no);
vi.push_back(no);
}
printf("%d\n", lis(vi));
return 0;
}
| 8 | CPP |
import math
import sys
from bisect import bisect_right, bisect_left, insort_right
from collections import Counter, defaultdict
from heapq import heappop, heappush
from itertools import accumulate, permutations, combinations
from sys import stdout
R = lambda: map(int, input().split())
n = int(input())
arr = list(R())
tps = [(0, 0)]
for x in arr:
i = bisect_left(tps, (x, -1)) - 1
tps.insert(i + 1, (x, tps[i][1] + 1))
if i + 2 < len(tps) and tps[i + 1][1] >= tps[i + 2][1]:
del tps[i + 2]
print(max(x[1] for x in tps)) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2034567891;
const long long int INF64 = 1234567890123456789ll;
int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
long long int power(long long int x, long long int y) {
long long int ans = 1;
while (y > 0) {
if (y & 1) ans = (ans * x) % 1000000007;
x = (x * x) % 1000000007;
y /= 2;
}
return ans;
}
int small[100005], arr[100005], parent[100005], n;
int binary_search(int sz, int value) {
int low = 0;
int high = sz - 1;
int mid;
while (low < high) {
mid = low + ((high - low) / 2);
if (arr[small[mid]] > value)
high = mid;
else if (arr[small[mid]] < value)
low = mid + 1;
else
return mid;
}
return low;
}
void LIS() {
int size = 0;
for (int i = 0; i < n; i++) {
if (i == 0) {
small[size] = i;
parent[i] = -1;
} else if (arr[i] <= arr[small[size]]) {
int pos = binary_search(size + 1, arr[i]);
small[pos] = i;
if (pos != 0) {
parent[i] = small[pos - 1];
}
} else {
size = size + 1;
small[size] = i;
parent[i] = small[size - 1];
}
}
cout << size + 1 << endl;
int pos = small[size];
vector<int> v;
while (size >= 0) {
v.push_back(arr[pos]);
pos = parent[pos];
size--;
}
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
LIS();
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 100;
int n, last, a[maxN], BIS[maxN];
void input() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
}
int find(int l, int r, int key) {
int now = (r + l) / 2;
if ((r - l == 1 && BIS[r] > key && BIS[r - 1] <= key))
return r;
else if (r - l == 1 && BIS[l] > key && BIS[l - 1] <= key)
return l;
else if (r == l && BIS[r] > key && BIS[r - 1] <= key)
return r;
else if (r - l == 1)
return 0;
else if (r == l)
return 0;
if (BIS[now] > key && BIS[now - 1] <= key)
return now;
else if (BIS[now] < key)
return find(now + 1, r, key);
else
return find(l, now - 1, key);
return 0;
}
int main() {
input();
last = 1;
BIS[1] = a[1];
for (int i = 2; i <= n; i++) {
BIS[0] = 0;
if (a[i] > BIS[last]) {
last++;
BIS[last] = a[i];
}
BIS[find(1, last, a[i])] = a[i];
}
cout << last << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
int f[1000001] = {0}, n;
int get(int i) {
int mx = 0;
while (i > 0) {
mx = (f[i] > mx) ? f[i] : mx;
i -= i & -i;
}
return mx;
}
void update(int i, int t) {
while (i <= 1000000) {
f[i] = (t > f[i]) ? t : f[i];
i += i & -i;
}
}
int main() {
int i, x, t, ans = 0;
scanf("%d", &n);
while (n--) {
scanf("%d", &x);
t = get(x - 1) + 1;
update(x, t);
ans = (t > ans) ? t : ans;
}
printf("%d", ans);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
bool cmp(const pair<int, int>& p1, const pair<int, int>& p2) {
return p1.first < p2.first;
}
int main() {
int n;
scanf("%d", &n);
vector<int> v;
for (int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
v.push_back(a);
}
vector<int> v1;
int res = n;
for (int i = 0; i < n; i++) {
int idx = upper_bound(v1.begin(), v1.end(), v[i]) - v1.begin();
if (idx != v1.size()) {
v1[idx] = v[i];
res--;
} else
v1.push_back(v[i]);
}
printf("%d\n", res);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, a[100000 + 5];
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
int lmax = 0, l;
vector<int> v;
for (int i = 0; i < n; i++) {
vector<int>::iterator it;
it = lower_bound(v.begin(), v.end(), a[i]);
l = (it - v.begin() + 1);
lmax = max(lmax, l);
if (it == v.end()) {
v.push_back(a[i]);
} else {
*it = a[i];
}
}
cout << lmax << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T sqr(T t) {
return t * t;
}
int a[100100], d[100100];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) d[i] = 1e9;
d[0] = -1e9;
for (int i = 1; i <= n; i++) {
int l = 0, r = n;
while (r - l > 1) {
int mid = (l + r) >> 1;
if (d[mid] <= a[i])
l = mid;
else
r = mid;
}
int pos;
if (d[l] > a[i])
pos = l;
else
pos = r;
if (d[pos - 1] < a[i] && a[i] < d[pos]) {
d[pos] = a[i];
}
}
int ans = 0;
for (int i = 1; i <= n; i++)
if (d[i] == 1e9)
break;
else
ans++;
cout << ans;
}
| 8 | CPP |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000,64000000")
using namespace std;
int n;
int a[100002];
void start();
int main() {
start();
return 0;
}
void start() {
for (int i = 1; i < 100002; ++i) {
a[i] = 1000000;
}
int max_ind = 1;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int z;
scanf("%d", &z);
int ind = lower_bound(a + 1, a + 100002, z) - a;
a[ind] = z;
max_ind = max(ind, max_ind);
}
printf("%d", max_ind);
return;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100001], m[100002], p[100002];
int main() {
int n, i, j, k, l = 0, lo, hi, mid, f;
scanf("%d", &n);
for (i = 0; i < n; ++i) scanf("%d", a + i);
for (i = 0; i < n; ++i) {
lo = 1;
hi = l;
while (lo <= hi) {
mid = ceil((lo + hi) / 2);
if (a[m[mid]] < a[i])
lo = mid + 1;
else
hi = mid - 1;
}
f = lo;
p[i] = m[f - 1];
m[f] = i;
if (f > l) l = f;
}
printf("%d", l);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100005], f[100005], p[100005];
int main() {
int n, pos = 0, ans = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
f[i] = 1;
for (int j = pos; j > 0; j--) {
if (a[i] >= a[p[j]]) {
f[i] = f[p[j]] + 1;
break;
}
}
pos = max(pos, f[i]);
p[f[i]] = i;
ans = max(ans, f[i]);
}
printf("%d\n", ans);
return 0;
}
| 8 | CPP |
def CeilIndex(A, l, r, key):
while (r - l > 1):
m = l + (r - l)//2
if (A[m] >= key):
r = m
else:
l = m
return r
def LongestIncreasingSubsequenceLength(A, size):
# Add boundary case,
# when array size is one
tailTable = [0 for i in range(size + 1)]
len = 0 # always points empty slot
tailTable[0] = A[0]
len = 1
for i in range(1, size):
if (A[i] < tailTable[0]):
# new smallest value
tailTable[0] = A[i]
elif (A[i] > tailTable[len-1]):
# A[i] wants to extend
# largest subsequence
tailTable[len] = A[i]
len+= 1
else:
# A[i] wants to be current
# end candidate of an existing
# subsequence. It will replace
# ceil value in tailTable
tailTable[CeilIndex(tailTable, -1, len-1, A[i])] = A[i]
return len
n=int(input())
l=list(map(int,input().split()))
print(LongestIncreasingSubsequenceLength(l, n))
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int f[120000], v, ans, x, i, n, j;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; ++i) {
scanf("%d", &x);
v = 0;
for (j = x; j; j -= j & (-j)) v = max(v, f[j]);
v++;
ans = max(ans, v);
for (j = x; j <= n; j += j & (-j)) f[j] = max(f[j], v);
}
printf("%d\n", ans);
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5;
int a[M];
int32_t main() {
int n;
cin >> n;
memset(a, 31, sizeof a);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a[lower_bound(a, a + M, x) - a] = x;
}
return cout << int(lower_bound(a, a + M, M) - a) << endl, 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[101000];
int ans;
int b[101000];
int f[101000];
void update(int x, int y) {
for (int i = x; i <= n; i += i & -i) b[i] = max(b[i], y);
}
int query(int x) {
int res = 0;
for (int i = x; i; i -= i & -i) res = max(res, b[i]);
return res;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
f[i] = query(a[i]) + 1;
update(a[i], f[i]);
ans = max(ans, f[i]);
}
cout << ans << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[111111], b[111111], len;
int main() {
int n, i;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
len = 1;
b[0] = a[0];
int tmp;
for (i = 1; i < n; i++) {
if (a[i] > b[len - 1])
b[len++] = a[i];
else {
tmp = lower_bound(b, b + len, a[i]) - b;
b[tmp] = a[i];
}
}
printf("%d\n", len);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, base, f[N];
int main() {
scanf("%d", &n);
for (base = 1; base < n; base <<= 1)
;
for (int i = 1; i <= n; i++) f[i] = n + 1;
for (int i = 1; i <= n; i++) {
int a;
scanf("%d", &a);
int j = lower_bound(f, f + n + 1, a) - f;
if (a < f[j]) f[j] = a;
}
int ans = n;
while (f[ans] == n + 1) ans--;
printf("%d\n", ans);
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int in[100005];
int dp[100005];
int main() {
int n;
scanf("%d", &n);
fill(dp, dp + 100005, 1000000000);
dp[0] = 0;
int ret = 0;
for (int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
int s = 0, e = 100005;
while (e - s > 1) {
int med = (s + e) / 2;
if (dp[med] < a)
s = med;
else
e = med;
}
dp[s + 1] = a;
ret = max(ret, s + 1);
}
printf("%d\n", ret);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000000000;
const int MOD = 1000000007;
int main() {
int _start = clock();
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> d(n + 10, +INF);
d[0] = -INF;
for (int i = 0; i < n; ++i) {
int j = upper_bound(d.begin(), d.end(), a[i]) - d.begin();
if (d[j - 1] < a[i] && a[i] < d[j]) {
d[j] = a[i];
}
}
int r = 0;
for (int i = 0; i < d.size(); ++i) {
if (d[i] != INF) {
r = i;
}
}
cout << r << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100002;
int N;
vector<int> ans, a;
vector<int> getLis(const vector<int> &a) {
vector<int> b;
vector<int> p(a.size());
if (a.empty()) return b;
b.push_back(0);
int u, v, mid;
for (size_t i = 1; i < a.size(); ++i) {
if (a[i] > a[b.back()]) {
p[i] = b.back();
b.push_back(i);
continue;
}
for (u = 0, v = b.size() - 1; u < v;) {
mid = u + ((v - u) >> 1);
if (a[b[mid]] < a[i])
u = mid + 1;
else
v = mid;
}
if (a[i] < a[b[u]]) {
b[u] = i;
if (u > 0) p[i] = b[u - 1];
}
}
for (u = b.size(), v = b.back(); u--; v = p[v]) b[u] = a[v];
return b;
}
int main() {
cin >> N;
a.resize(N);
for (int i = 0; i < N; i++) {
cin >> a[i];
}
ans = getLis(a);
cout << ans.size();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, i, a[100101], ans[100101], out;
int T[400001];
int query(int v, int tl, int tr, int l, int r) {
if (l > r) return 0;
if (tl == l && tr == r) {
return T[v];
};
int tm = (tl + tr) / 2;
return max(query(2 * v, tl, tm, l, min(tm, r)),
query(2 * v + 1, tm + 1, tr, max(tm + 1, l), r));
};
void update(int v, int tl, int tr, int pos, int val) {
if (tl == tr) {
T[v] = val;
return;
};
int tm = (tl + tr) / 2;
if (tm >= pos)
update(2 * v, tl, tm, pos, val);
else
update(2 * v + 1, tm + 1, tr, pos, val);
T[v] = max(T[2 * v], T[2 * v + 1]);
};
int main() {
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = 1; i <= n; i++) {
ans[a[i]] = query(1, 1, n, 1, a[i] - 1) + 1;
update(1, 1, n, a[i], ans[a[i]]);
out = max(out, ans[a[i]]);
};
cout << out;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int mxn = 2e5;
int n;
vector<int> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
auto it = lower_bound(v.begin(), v.end(), a);
if (it != v.end())
*it = a;
else
v.push_back(a);
}
cout << v.size();
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<int> LIS(vector<int> A) {
int N = A.size(), i, j = -1, t;
vector<int> pre(N, -1), res;
map<int, int> m;
map<int, int>::iterator k, l;
for (i = 0; i < N; i++) {
if (m.insert(pair<int, int>(A[i], i)).second) {
k = m.find(A[i]);
l = k;
k++;
if (l == m.begin())
pre[i] = -1;
else {
l--;
pre[i] = l->second;
}
if (k != m.end()) m.erase(k);
}
}
k = m.end();
k--;
j = k->second;
while (j != -1) {
res.push_back(A[j]);
j = pre[j];
}
reverse(res.begin(), res.end());
return res;
}
int n, aux;
vector<int> a;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &aux);
a.push_back(aux);
}
printf("%d\n", (LIS(a)).size());
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int leap[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a[111111], n;
vector<int>::iterator it;
int lis() {
vector<int> v;
v.push_back(-1);
for (int i = 0; i < n; ++i)
if (a[i] >= v[v.size() - 1])
v.push_back(a[i]);
else {
it = upper_bound(v.begin(), v.end(), a[i]);
*it = a[i];
}
return v.size() - 1;
}
int main() {
while (scanf("%d", &n) == 1) {
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
cout << lis() << endl;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100010];
multiset<int> s;
multiset<int>::iterator sit;
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
s.insert(a[1]);
for (int i = 2; i <= n; i++) {
sit = s.upper_bound(a[i]);
if (sit != s.end()) {
s.erase(sit);
}
s.insert(a[i]);
}
printf("%d\n", s.size());
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long inf = 1LL << 62;
static long parseans(long j, long l) {
string k = "";
long ps = 0;
for (long long i = (long long)j; i <= l; ++i) {
ps *= 10;
ps += k[i] - '0';
}
return ps;
}
int cur = 1;
int cnt = 0;
static long gcd(long a, long b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
static bool pri(long long k) {
if (k == 1LL) return false;
for (long long i = 2; i * i <= k; i++) {
if (k % i == 0) return false;
}
return true;
}
int n, k;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
int a[1000005];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> dp(n);
dp[0] = -1000005;
for (int i = 1; i <= n; i++) {
dp[i] = 1000005;
}
int ans = 0;
for (int i = 0; i < n; i++) {
int j = int(upper_bound(dp.begin(), dp.end(), a[i]) - dp.begin());
if (dp[j - 1] < a[i] && a[i] < dp[j]) {
dp[j] = a[i];
}
}
for (int i = 0; i <= n; i++) {
if (abs(dp[i]) != 1000005) ans++;
}
cout << ans << "\n";
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int dp[100001];
int main() {
long long int n;
cin >> n;
for (long long int i = 0; i < ((long long int)(n)); i++) {
cin >> a[i];
}
for (long long int i = 0; i < ((long long int)(n)); i++) dp[i] = 1e+9;
for (long long int i = 0; i < ((long long int)(n)); i++)
*upper_bound(dp, dp + n, a[i]) = a[i];
cout << find(dp, dp + n, 1e+9) - dp << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
struct bit {
int v[200000];
bit() { memset(v, 0, sizeof v); }
int query(int p) {
int resp = 0;
for (int i = p; i > 0; i -= (i & (-i))) resp = max(resp, v[i]);
return resp;
}
void set(int p, int val) {
for (int i = p; i < 200000; i += (i & (-i))) v[i] = max(val, v[i]);
}
};
int main() {
scanf("%d", &n);
bit bt;
int resp = 0;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
bt.set(x, bt.query(x - 1) + 1);
}
printf("%d\n", bt.query(150000));
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long int bit[100009] = {0}, m = -1, n;
void update(long long int i, long long int val) {
while (i <= n) {
bit[i] = max(val, bit[i]);
i += (i & (-i));
}
}
long long int query(long long int i) {
long long int sum = 0;
while (i > 0) {
sum = max(sum, bit[i]);
i -= (i & (-i));
}
return sum;
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
long long int i, x;
cin >> n;
for (i = 0; i < n; i++) {
cin >> x;
m = max(m, x);
update(x, query(x) + 1);
}
cout << query(n) << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100010] = {}, dp[100010] = {}, ii, mx = 0;
cin >> n;
fill(dp, dp + n + 10, 1000000);
for (int i = 0; i < n; i++) {
cin >> a[i];
ii = upper_bound(dp, dp + n, a[i]) - dp;
dp[ii] = a[i];
mx = max(mx, ii);
}
cout << mx + 1;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 4;
struct Node {
int best = 0;
} st[4 * MAX_N];
int get(int p, int l, int r, int x, int y) {
if (l > y || r < x) return 0;
if (l >= x && r <= y) return st[p].best;
int mid = (l + r) >> 1;
int f = get(2 * p + 1, l, mid, x, y);
int s = get(2 * p + 2, mid + 1, r, x, y);
return max(f, s);
}
void update(int p, int l, int r, int x, int val) {
if (l > x || r < x) return;
if (l == r) {
st[p].best = val;
return;
}
int mid = (l + r) >> 1;
update(2 * p + 1, l, mid, x, val);
update(2 * p + 2, mid + 1, r, x, val);
st[p].best = max(st[2 * p + 1].best, st[2 * p + 2].best);
}
int main() {
int n;
scanf("%d", &n);
int res = 0;
for (int i = 0; i < n; i++) {
int v;
scanf("%d", &v);
int gt = get(0, 0, n - 1, 1, v - 1) + 1;
res = max(res, gt);
update(0, 0, n - 1, v, gt);
}
cout << res << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
set<int> st;
int n, x;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &x);
st.insert(x);
auto it = st.upper_bound(x);
if (it != st.end()) st.erase(it);
}
printf("%d\n", int(st.size()));
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, arr[100005];
vector<int> v;
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < n; i++) {
int pos = upper_bound(v.begin(), v.end(), arr[i]) - v.begin();
if (pos == v.size())
v.push_back(arr[i]);
else
v[pos] = arr[i];
}
cout << v.size() << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int a[N], C[N], f[N];
int bsearch(const int *C, int size, const int &a) {
int l = 0, r = size - 1;
while (l <= r) {
int mid = (l + r) / 2;
if (a > C[mid - 1] && a <= C[mid])
return mid;
else if (a < C[mid])
r = mid - 1;
else
l = mid + 1;
}
}
int LIS(const int *a, const int &n) {
int i, j, size = 1;
C[0] = a[0];
f[0] = 1;
for (i = 1; i < n; ++i) {
if (a[i] <= C[0])
j = 0;
else if (a[i] > C[size - 1])
j = size++;
else
j = bsearch(C, size, a[i]);
C[j] = a[i];
f[i] = j + 1;
}
return size;
}
int main() {
int testcase;
int n;
int i, j;
scanf("%d", &n);
for (j = 0; j < n; j++) scanf("%d", &a[j]);
printf("%d\n", LIS(a, n));
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const double eps = 1e-8;
const long long linf = 1e18;
int a[111111], c[111111], dp[111111];
long long gcd(long long a, long long b) {
if (a < b) swap(a, b);
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int bsearch(int c[], int n, int a) {
int l = 1, r = n;
while (l <= r) {
int mid = (l + r) / 2;
if (a > c[mid] && a <= c[mid + 1])
return mid + 1;
else if (a < c[mid])
r = mid - 1;
else
l = mid + 1;
}
}
int LIS(int a[], int n) {
int i, j, size = 1;
c[1] = a[1];
dp[1] = 1;
for (i = 2; i <= n; ++i) {
if (a[i] <= c[1])
j = 1;
else if (a[i] > c[size])
j = ++size;
else
j = bsearch(c, size, a[i]);
c[j] = a[i];
dp[i] = j;
}
return size;
}
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
cout << LIS(a, n) << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int rands() {
static int x = 1364684679;
x += (x << 2) + 1;
return x;
}
struct point {
double x, y;
int init() { return scanf("%lf%lf", &x, &y); }
point operator+(point a) {
point ret;
ret.x = x + a.x;
ret.y = y + a.y;
return ret;
}
point operator-(point a) {
point ret;
ret.x = x - a.x;
ret.y = y - a.y;
return ret;
}
double operator*(point a) { return x * a.y - y * a.x; }
double operator^(point a) { return x * a.x + y * a.y; }
};
struct circle {
point o;
double r;
};
struct point3 {
double x, y, z;
int init() { return scanf("%lf%lf%lf", &x, &y, &z); }
point3 operator+(point3 a) {
point3 ret;
ret.x = x + a.x;
ret.y = y + a.y;
ret.z = z + a.z;
return ret;
}
point3 operator-(point3 a) {
point3 ret;
ret.x = x - a.x;
ret.y = y - a.y;
ret.z = z - a.z;
return ret;
}
point3 operator*(point3 a) {
point3 ret;
ret.x = y * a.z - z * a.y;
ret.y = z * a.x - x * a.z;
ret.z = x * a.y - y * a.x;
return ret;
}
double operator^(point3 a) { return x * a.x + y * a.y + z * a.z; }
};
double xmult(point p0, point p1, point p2) {
return (p1.x - p0.x) * (p2.y - p0.y) - (p1.y - p0.y) * (p2.x - p0.x);
}
point3 xmult3(point3 p0, point3 p1, point3 p2) {
point3 ret;
ret.x = (p1.y - p0.y) * (p2.z - p0.z) - (p1.z - p0.z) * (p2.y - p0.y);
ret.y = (p1.z - p0.z) * (p2.x - p0.x) - (p1.x - p0.x) * (p2.z - p0.z);
ret.z = (p1.x - p0.x) * (p2.y - p0.y) - (p1.y - p0.y) * (p2.x - p0.x);
return ret;
}
double dot(point a, point b) { return a.x * b.x + a.y * b.y; }
double dot3(point3 a, point3 b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
double dist(point a, point b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double dist3(point3 a, point3 b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) +
(a.z - b.z) * (a.z - b.z));
}
struct matrix {
int n;
int a[40][40];
void clear() { memset(a, 0, sizeof(a)); }
void init() {
clear();
for (int i = 1; i <= n; i++) a[i][i] = 1;
}
matrix operator*(matrix b) {
matrix c;
c.n = n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
c.a[i][j] = 0;
for (int k = 1; k <= n; k++) c.a[i][j] += a[i][k] * b.a[k][j];
}
return c;
}
matrix operator+(matrix b) {
matrix c;
c.n = n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) c.a[i][j] = a[i][j] + b.a[i][j];
return c;
}
void printmatrix() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) printf("%d ", a[i][j]);
printf("\n");
}
}
};
struct bignumber {
int n;
int a[10010];
void clear() {
n = 0;
memset(a, 0, sizeof(a));
}
void init(char *s) {
clear();
n = strlen(s);
for (int i = 0; s[i]; i++) a[n - i] = s[i] - '0';
while (a[n] == 0 && n > 1) n--;
}
void init(int s) {
clear();
if (s == 0) {
n = 1;
a[1] = 0;
return;
}
while (s) {
a[++n] = s % 10;
s /= 10;
}
}
void output() {
for (int i = n; i > 0; i--) printf("%d", a[i]);
printf("\n");
}
int operator<(bignumber b) {
if (n < b.n) return 1;
if (n > b.n) return 0;
for (int i = n; i > 0; i--) {
if (a[i] < b.a[i]) return 1;
if (a[i] > b.a[i]) return 0;
}
return 0;
}
int operator==(bignumber b) {
if (n != b.n) return 0;
for (int i = n; i > 0; i--)
if (a[i] != b.a[i]) return 0;
return 1;
}
};
bignumber operator+(bignumber a, bignumber b) {
a.n = max(a.n, b.n);
for (int i = 1; i <= a.n; i++) {
a.a[i] += b.a[i];
a.a[i + 1] += a.a[i] / 10;
a.a[i] %= 10;
}
if (a.a[a.n + 1] > 0) a.n++;
return a;
}
bignumber operator-(bignumber a, bignumber b) {
for (int i = 1; i <= a.n; i++) {
a.a[i] -= b.a[i];
if (a.a[i] < 0) {
a.a[i + 1]--;
a.a[i] += 10;
}
}
while (a.a[a.n] == 0 && a.n > 1) a.n--;
return a;
}
bignumber operator*(bignumber a, int b) {
for (int i = 1; i <= a.n; i++) {
a.a[i] = a.a[i] * b + a.a[i - 1] / 10;
a.a[i - 1] %= 10;
}
while (a.a[a.n] >= 10) {
a.n++;
a.a[a.n] = a.a[a.n - 1] / 10;
a.a[a.n - 1] %= 10;
}
return a;
}
bignumber operator/(bignumber a, int b) {
int tmp = 0;
for (int i = a.n; i > 0; i--) {
tmp = tmp * 10 + a.a[i];
a.a[i] = tmp / b;
tmp %= b;
}
while (a.a[a.n] == 0 && a.n > 1) a.n--;
return a;
}
bignumber gcd(bignumber a, bignumber b) {
int ans = 0;
bignumber c;
while (1) {
if (a.n == 1 && a.a[1] == 0) {
c = b;
break;
}
if (b.n == 1 && b.a[1] == 0) {
c = a;
break;
}
int flag = 0;
if (a.a[1] % 2 == 0) a = a / 2, flag++;
if (b.a[1] % 2 == 0) b = b / 2, flag++;
if (flag == 2) ans++;
if (!flag)
if (a < b)
b = b - a;
else
a = a - b;
}
while (ans--) c = c * 2;
return c;
}
int fastget() {
char c;
int ans = 0;
c = getchar();
int sign = 1;
while (!(c >= '0' && c <= '9' || c == '-')) c = getchar();
if (c == '-') sign = -1, c = getchar();
while (c >= '0' && c <= '9') {
ans = (ans << 3) + (ans << 1) + c - '0';
c = getchar();
}
return ans * sign;
}
void fastput(int x) {
char s[12];
int a = 0;
if (x == 0)
puts("0");
else {
if (x < 0) putchar('-'), x = -x;
while (x) {
s[a++] = x % 10 + '0';
x /= 10;
}
for (a--; a >= 0; a--) putchar(s[a]);
putchar('\n');
}
}
int n, a;
int tree[100010 << 2];
int query(int L, int R, int l, int r, int rt) {
if (L <= l && R >= r) return tree[rt];
int mid = l + r >> 1, ret = 0;
if (L <= mid) ret = max(ret, query(L, R, l, mid, rt << 1));
if (R > mid) ret = max(ret, query(L, R, mid + 1, r, rt << 1 | 1));
return ret;
}
void update(int i, int x, int l, int r, int rt) {
if (l == r) {
tree[rt] = x;
return;
}
int mid = l + r >> 1;
if (i <= mid)
update(i, x, l, mid, rt << 1);
else
update(i, x, mid + 1, r, rt << 1 | 1);
tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]);
}
int main() {
n = fastget();
memset(tree, 0, sizeof(tree));
int ans = 0;
for (int i = 1; i <= n; ++i) {
scanf("%d", &a);
int lcs = query(1, a, 1, n, 1);
ans = max(ans, lcs + 1);
update(a, lcs + 1, 1, n, 1);
}
printf("%d\n", ans);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int a[MAXN];
int dp[MAXN];
int q[MAXN];
int n;
void cc() {
int top = 0;
for (int i = 1; i <= n; i++) {
if (top == 0 || dp[top] < a[i]) {
dp[++top] = a[i];
continue;
}
int l = 1, r = top;
int ans = 1;
while (l <= r) {
int mid = (l + r) >> 1;
if (dp[mid] < a[i])
l = mid + 1;
else {
ans = mid;
r = mid - 1;
}
}
dp[ans] = a[i];
}
cout << top << endl;
}
int main() {
while (cin >> n) {
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
cc();
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100005], n;
void update(int i, int v) {
for (; i < n; i = i | (i + 1)) a[i] = max(a[i], v);
}
int get(int i) {
int len = 0;
for (; i >= 0; i = (i & (i + 1)) - 1) len = max(len, a[i]);
return len;
}
int main() {
int mx, x, i, ans = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> x;
mx = get(x - 1);
update(x, mx + 1);
ans = max(ans, mx + 1);
}
cout << ans;
return 0;
}
| 8 | CPP |
def CeilIndex(A, l, r, key):
while (r - l > 1):
m = l + (r - l)//2
if (A[m] >= key):
r = m
else:
l = m
return r
def LIS(A, size):
tailTable = [0 for i in range(size + 1)]
len = 0
tailTable[0] = A[0]
len = 1
for i in range(1, size):
if (A[i] < tailTable[0]):
tailTable[0] = A[i]
elif (A[i] > tailTable[len-1]):
tailTable[len] = A[i]
len+= 1
else:
tailTable[CeilIndex(tailTable, -1, len-1, A[i])] = A[i]
return len
def main():
n = int(input())
arr = list(map(int,input().split()))
print(LIS(arr,n))
main()
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const int XD = 100100;
int a[XD];
int dp[XD];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
}
dp[0] = -1;
for (int i = 1; i <= n; ++i) {
dp[i] = INF;
}
int lim = 1;
for (int i = 0; i < n; ++i) {
int lf = 0, rg = lim;
while (lf < rg) {
int mid = (lf + rg) >> 1;
if (a[i] > dp[mid]) {
lf = mid + 1;
} else {
rg = mid;
}
}
dp[lf] = a[i];
lim = max(lim, lf + 1);
}
printf("%d\n", lim - 1);
return 0;
}
| 8 | CPP |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.