Submission #100105

#TimeUsernameProblemLanguageResultExecution timeMemory
100105shafinalamGlobal Warming (CEOI18_glo)C++14
100 / 100
88 ms4736 KiB
#include <bits/stdc++.h>

using namespace std;

const int mx = 2e5+5;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<int,pii>piii;

#define  sf scanf
#define  pf printf

#define  input freopen("input.txt","r",stdin)
#define  output freopen("output.txt","w",stdout)

#define  inf 1e16
#define  ff first
#define  ss second
#define  MP make_pair
#define  pb push_back
#define  all(v) v.begin(), v.end()
#define  printcase(cases) printf("Case %d:", cases);
#define  Unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define  FAST  ios_base::sync_with_stdio(0);cout.tie(0)
#define  endl printf("\n")
#define  __lcm(a, b) ((a*b)/__gcd(a, b))

int  Set(int N,int pos){return N=N | (1<<pos);}
int  reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}

int suf[mx];
int arr[mx];
int n, x;

void LDS()
{
    vector<int>v;
    for(int i = 0; i < n; i++) v.push_back(0);
    for(int i = n-1; i >= 0; i--)
    {
        int it = upper_bound(all(v), arr[i])-v.begin()-1;
        v[it] = arr[i];
        suf[i] = n-it;
    }
}
void LIS()
{
    int ans = 0;
    vector<int>v;
    for(int i = 0; i < n; i++)
    {
        int pos = lower_bound(all(v), arr[i]+x)-v.begin();
        ans = max(ans, suf[i]+pos);
        auto it = lower_bound(all(v), arr[i]);
        if(it==v.end()) v.push_back(arr[i]);
        else v[it-v.begin()] = arr[i];
    }
    pf("%d\n", ans);
}
int main()
{
    sf("%d%d", &n, &x);

    for(int i = 0; i < n; i++) sf("%d", &arr[i]);
    LDS();
    LIS();
    return 0;
}

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     sf("%d%d", &n, &x);
       ^
glo.cpp:67:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 0; i < n; i++) sf("%d", &arr[i]);
                                  ^
#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...