Submission #1268034

#TimeUsernameProblemLanguageResultExecution timeMemory
1268034rafamiuneGlobal Warming (CEOI18_glo)C++20
10 / 100
114 ms9840 KiB
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define int long long
#define all(x) (x).begin(), (x).end()
const int maxn = 2e5 + 5;
const long long inf = 1e18 + 5;

vector<int> tr(4*maxn), v(maxn);

void update(int node, int l, int r, int pos, int x) {

    if(l == r) {
        tr[node] = x;
        return;
    }
    int mid = (l+r)/2, lc = 2*node + 1, rc = 2*node + 2;
    if(pos <= mid) update(lc, l, mid, pos, x);
    else if(pos > mid) update(rc, mid + 1, r, pos, x);
    tr[node] = max(tr[lc], tr[rc]);
}

int query(int node, int l, int r, int ll, int rr) {

    if(l > rr || r < ll) {
        return -1;
    }
    if(l >= ll && r <= rr) {
        return tr[node];
    }
    int mid = (l+r)/2, lc = 2*node + 1, rc = 2*node + 2;
    return max(query(lc, l, mid, ll, rr), query(rc, mid + 1, r, ll, rr));
}

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n; 
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> v[i];
    }
    vector<int> aux;
    aux =  v;
    sort(all(aux));
    aux.erase(unique(all(aux)), aux.end());
    for(int i = 1; i <= n; i++) {
        v[i] = lower_bound(all(aux), v[i]) - aux.begin() + 1;
    }
    for(int i = 1; i <= n; i++) {
        int max_dp = query(0, 1, n, 1, v[i] - 1);
        update(0, 1, n, v[i], max_dp + 1);
    }

    cout << query(0, 1, n, 1, n);
    
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...