Submission #840508

#TimeUsernameProblemLanguageResultExecution timeMemory
840508c2zi6Global Warming (CEOI18_glo)C++14
0 / 100
255 ms10444 KiB
#include <bits/stdc++.h>
#define ff first
#define ss second

using namespace std;
using ll = long long;

class SEG {
    public:
        SEG(int m) {
            n = 1;
            while (n < m) n <<= 1;
            tree = vector<int>(2 * n);
        }
        void add(int h, int s) {
            this->update(0, 0, n-1, h, s);
        }
        int opt(int l, int r) {
            l = max(l, 0);
            r = min(r, n-1);
            return this->get(0, 0, n-1, l, r);
        }
        void print() {
            for (int i = 0; i < n; i++) cout << this->opt(i, i) << " "; cout << endl;
        }
    private:
        int n;
        vector<int> tree;
        int get(int N, int L, int R, int l, int r) {
            if (l <= L && R <= r) return tree[N];
            if (R < l || L > r) return 0;
            int M = (L + R) / 2;
            return max(get(2*N+1, L, M, l, r), get(2*N+2, M+1, R, l, r));
        }
        int update(int N, int L, int R, int i, int x) {
            if (i < L || i > R) return 0;
            if (L == R) return tree[N] = max(tree[N], x);;
            int M = (L + R) / 2;
            return tree[N] = max(update(2*N+1, L, M, i, x), update(2*N+2, M+1, R, i, x));
        }
};

void compress(vector<int>& a) {
    map<int, int> mp;
    for (int x : a) mp[x] = 0;
    int i = 0;
    for (pair<int, int> p : mp) mp[p.ff] = i++;
    for (int& x : a) x = mp[x];
}

void solve() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int& x : a) cin >> x;
    compress(a);
    //for (int x : a) cout << x << " "; cout << endl;

    SEG seg(n);
    for (int x : a) {
        seg.add(x, seg.opt(-2e9, x-1)+1);
    }
    
    cout << seg.opt(-2e9, +2e9) << endl;
}

int main() {
	int t = 1;
    //cin >> t;
    while (t--) solve();
}

Compilation message (stderr)

glo.cpp: In member function 'void SEG::print()':
glo.cpp:24:13: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   24 |             for (int i = 0; i < n; i++) cout << this->opt(i, i) << " "; cout << endl;
      |             ^~~
glo.cpp:24:73: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   24 |             for (int i = 0; i < n; i++) cout << this->opt(i, i) << " "; cout << endl;
      |                                                                         ^~~~
#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...