Submission #434971

#TimeUsernameProblemLanguageResultExecution timeMemory
434971nguotGlobal Warming (CEOI18_glo)C++14
0 / 100
66 ms5312 KiB
#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 (stderr)

glo.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main()
      | ^~~~
#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...