Submission #827864

# Submission time Handle Problem Language Result Execution time Memory
827864 2023-08-16T20:59:20 Z BT21tata Lottery (CEOI18_lot) C++17
0 / 100
2 ms 468 KB
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define SPEED ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define rall(v) (v).rbegin(),(v).rend()
#define all(v) (v).begin(),(v).end()
#define setp fixed<<setprecision
#define OK cerr<<"OK"<<endl<<flush
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define F first
#define S second
#define y0 jahdakdh
#define y1 jahsadakdakdh
#define endl '\n'
const ll MOD=1e9+7;
const ll mod=(1ll<<31)-1;
const ld eps=1e-8;
const ll MAXLONG=9223372036854775807;
const ll MINLONG=-9223372036854775807;
using namespace std;
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
const int N=2e5+5;

int n, x, a[N], ans, fs[N];

vector<int> LIS()
{
    vector<int>v{a[0]}, ret{1};
    for(int i=1; i<n; i++)
    {
        if(v.back()<a[i])
        {
            v.pb(a[i]);
            ret.pb(v.size());
        }
        else
        {
            int pos=lower_bound(all(v), a[i])-v.begin();
            v[pos]=a[i];
            ret.pb(pos+1);
        }
    }
    return ret;
}

int main()
{
    SPEED;
    cin>>n>>x;
    for(int i=0; i<n; i++)
        cin>>a[i];
    vector<int>l = LIS();
    
    reverse(a, a+n);
    for(int i=0; i<n; i++)
        a[i]=-a[i];
    vector<int>r = LIS();

    reverse(a, a+n);
    for(int i=0; i<n; i++)
        a[i]=-a[i];
    a[n]=2*MOD;

    for(int i=n-1; i>=0; i--)
    {
        fs[i]=i+1;
        while(a[fs[i]]+x<=a[i]) fs[i]=fs[fs[i]];
        //cout<<i<<' '<<l[i]<<' '<<r[i]<<' '<<fs[i]<<endl;
        ans=max(ans, l[i]+r[fs[i]]);
    }
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -