Submission #1007697

# Submission time Handle Problem Language Result Execution time Memory
1007697 2024-06-25T10:32:02 Z andecaandeci Global Warming (CEOI18_glo) C++17
17 / 100
38 ms 7812 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i=a; i<=(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b); i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define int long long
#define ld long double
#define lb lower_bound
#define ceil(a,b) (a+(b-1))/b
#define ins insert
#define ub upper_bound
#define pb push_back
#define VI vector<int> 
#define VVI vector<VI> 
#define PII pair<int,int> 
#define VII vector<PII> 
#define size(x) x.size()
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const int mod = 1e9+7;
const int N = 2e5 + 5;
// const int mod = 998244353;
int binser(vector<int>&temp,int num){
    int l =0,r=size(temp)-1,ind,mid;
    while(l<=r){
        mid=(l+r)/2;
        if(num>=temp[mid]){
            ind=mid;
            r=mid-1;
        }
        else{
            l=mid+1;
        }
    }
    // if(num>=temp[ind]){
        return ind;

    // }
    // else return -1;
}
void solve(){
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i =0 ;i<n;i++){
        cin>>arr[i];
    }
    int inc[n],linc[n];
    inc[0]=arr[0];
    linc[0]=1;
    vector<int> temp;
    int ans=0;
    temp.push_back(arr[0]);
    for (int i = 1; i < n; i++) {
        if (arr[i] > temp.back()) {
            temp.push_back(arr[i]);
        } else {
            int ind = lower_bound(temp.begin(), temp.end(), arr[i]) - temp.begin();
            temp[ind] = arr[i];
        }
        inc[i]=temp.back();
        linc[i]=size(temp);
    }
    // for(int i =0;i<n;i++){
    //     cout<<inc[i]<<" "<<linc[i]<<endl;
    // }
    // trav(it,temp){
    //     cout<<it<<" ";
    // }
    ans=size(temp);
    temp.clear();
    temp.push_back(arr[n-1]);
    for (int i = n-2; i >= 0; i--) {
        // trav(it,temp){
        //     cout<<it<<" ";
        // }
        // cout<<endl;
        ans=max(ans,(int)(linc[i]+(size(temp)-binser(temp,inc[i]-k+1))));

        if (arr[i] < temp.back()) {
            temp.push_back(arr[i]);
        } else {
            int ind=binser(temp,arr[i]);
            temp[ind] = arr[i];
        }
        

    }



    cout<<ans<<endl;


}


int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cout<<setprecision(12)<<fixed;
    // cin>>t; 
    while(t--){
        
        solve();
    }
}

Compilation message

glo.cpp: In function 'long long int binser(std::vector<long long int>&, long long int)':
glo.cpp:39:16: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   39 |         return ind;
      |                ^~~
glo.cpp: In function 'void solve()':
glo.cpp:81:53: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   81 |         ans=max(ans,(int)(linc[i]+(size(temp)-binser(temp,inc[i]-k+1))));
      |                                               ~~~~~~^~~~~~~~~~~~~~~~~
glo.cpp:87:21: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   87 |             temp[ind] = arr[i];
      |                     ^
# 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 Incorrect 0 ms 348 KB Output isn't correct
6 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 Incorrect 0 ms 348 KB Output isn't correct
6 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 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 6992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 3672 KB Output is correct
2 Correct 16 ms 3676 KB Output is correct
3 Correct 34 ms 7004 KB Output is correct
4 Correct 18 ms 7388 KB Output is correct
5 Correct 11 ms 3804 KB Output is correct
6 Correct 15 ms 7132 KB Output is correct
7 Correct 18 ms 7812 KB Output is correct
8 Correct 14 ms 3676 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 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -