Submission #434971

# Submission time Handle Problem Language Result Execution time Memory
434971 2021-06-22T16:28:43 Z nguot Global Warming (CEOI18_glo) C++14
0 / 100
66 ms 5312 KB
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0)
#define fori(x,a,b) for (int x=a;x<=b;++x)
#define ford(x,a,b) for (int x=a;x>=b;x--)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define mp make_pair
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define getbit(x,i) ((x>>i)&1)
#define batbit(x,i) (x|(1ll<<i))
#define tatbit(x,i) (x&~(1<<i))
#define gg exit(0);

const int N = 2e5 + 10;
int n,x,a[N],pref[N];
main()
{
    //freopen("task.inp","r",stdin);
    fasty;
    cin>>n>>x;
    fori(i,1,n) cin>>a[i];

    vector<int> dp(n,INT_MAX);
    int res = 0;
    fori(i,1,n)
    {
        int j = lower_bound(all(dp),a[i]) - dp.begin();
        pref[i] = j+1;
        dp[j] = a[i];
        res = max(res,j+1);
    }
    dp = vector<int>(n,INT_MAX);
    // longest decreasing subsequence ending at i of reverse
	// = longest increasing subsequence starting at i
    ford(i,n,1)
    {
        int j = lower_bound(all(dp),-(a[i]-x)) - dp.begin();//gia su 1->i ta giam tat ca cac ptu di x;
        res = max(pref[i]+j,res);
        int pos = lower_bound(all(dp),-a[i]) - dp.begin();
        dp[pos] = -a[i];
    }
    cout<<res+1;
}

Compilation message

glo.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 66 ms 5312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 2840 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -