Submission #1050333

# Submission time Handle Problem Language Result Execution time Memory
1050333 2024-08-09T08:47:52 Z anton Global Warming (CEOI18_glo) C++17
27 / 100
156 ms 9148 KB
#include<bits/stdc++.h>

using namespace std;
int N, X;


struct MaxTree{
    int len = 1;
    vector<int> tr;
    MaxTree(int n){
        while(len<n){
            len*=2;
        }
        tr.resize(2*len);
    }

    void upd(int u){
        for(u/=2; u>=1; u/=2){
            tr[u] = max(tr[u*2], tr[u*2+1]);
        }
    }

    int get(int l, int r){
        l += len;
        r+=len+1;
        int res = 0;
        for(; l<r; l/=2, r/=2){
            if(l%2 ==1){
                res = max(res, tr[l++]);
            }
            if(r%2 == 1){
                res = max(res, tr[--r]);
            }
        }
        return res;
    }

    void set(int pos, int val){
        pos+=len;
        tr[pos] = max(tr[pos], val);
        upd(pos);
    }
};

int find_pos(int e, vector<int>& v){
    int pos =0;
    for(int step = (1<<20); step>=1; step/=2){
        if(pos+step<v.size() && v[pos+step]<=e){
            pos+=step;
        }
    }
    return pos;
}

vector<int> vals;

int lis(vector<int>& v){
    MaxTree tr(vals.size());

    for(int i= 0; i<N; i++){
        int pos_above = find_pos(vals[v[i]] + X, vals);
        int best_above = tr.get(0, pos_above-1);
        tr.set(pos_above, best_above+1);
        int best_under = tr.get(0, v[i]-1);
        tr.set(v[i], best_under+1);
    }

    return tr.get(0, vals.size()-1);
}
signed main(){
    cin>>N>>X;
    vector<int> t(N);
    vals.push_back(0);
    for(int i = 0; i<N; i++){
        cin>>t[i];
        vals.push_back(t[i]);
        vals.push_back(t[i]+X);
    }


    sort(vals.begin(), vals.end());

    for(int i = 0; i<N; i++){
        t[i] = find_pos(t[i], vals);
    }



    
    
    cout<<lis(t)<<endl;
    
}

Compilation message

glo.cpp: In function 'int find_pos(int, std::vector<int>&)':
glo.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         if(pos+step<v.size() && v[pos+step]<=e){
      |            ~~~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 0 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 0 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 0 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 150 ms 8900 KB Output is correct
2 Correct 153 ms 8920 KB Output is correct
3 Correct 152 ms 9148 KB Output is correct
4 Correct 145 ms 8736 KB Output is correct
5 Correct 104 ms 8128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2668 KB Output is correct
2 Correct 32 ms 2512 KB Output is correct
3 Correct 31 ms 2552 KB Output is correct
4 Incorrect 28 ms 2260 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 73 ms 4560 KB Output is correct
2 Correct 70 ms 4748 KB Output is correct
3 Correct 156 ms 8900 KB Output is correct
4 Correct 93 ms 8180 KB Output is correct
5 Correct 48 ms 4304 KB Output is correct
6 Correct 102 ms 8092 KB Output is correct
7 Correct 104 ms 8640 KB Output is correct
8 Correct 63 ms 4552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 0 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -