제출 #1197107

#제출 시각아이디문제언어결과실행 시간메모리
1197107SSSMGlobal Warming (CEOI18_glo)C++20
27 / 100
279 ms13940 KiB
#include <bits/stdc++.h> /* #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC target ("avx2") */ using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; */ #define F first #define S second #define pb push_back #define FIO freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout) #define md(a) ((a%mod+mod)%mod) #define all(a) a.begin(), a.end() #define MP make_pair #define lc (id<<1) #define rc (lc|1) #define mid (l+r)/2 #define kill(a) cout << a << "\n", exit(0) #define SZ(a) (ll)a.size() typedef pair<int,int> pii; typedef pair<long long ,long long> pll; typedef long long ll; typedef long double ld; typedef vector<vector<ll>> matrix; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll const maxn=4e5+10, mod=1e9+7, INF=1e18, LOG=20, sq=65; ll poww(ll a, ll b, ll mod) { if (b == 0) return 1; return 1 * poww(1 * a * a % mod, b / 2, mod) * ((b % 2 == 1) ? a : 1) % mod; } ll n, k, seg[2][maxn<<2], A[maxn], N; vector<ll> comp; ll GI(ll a) { return lower_bound(all(comp), a)-comp.begin(); } void Upd(ll ind, ll p, ll x, ll l=0, ll r=N, ll id=1) { if(l==r-1) { seg[ind][id]=max(seg[ind][id], x); return; } if(p<mid) Upd(ind, p, x, l, mid, lc); else Upd(ind, p, x, mid, r, rc); seg[ind][id]=max(seg[ind][lc], seg[ind][rc]); } ll Get(ll ind, ll s, ll e, ll l=0, ll r=N, ll id=1) { if(l>=e || r<=s) return -INF; if(s<=l && r<=e) return seg[ind][id]; return max(Get(ind, s, e, l, mid, lc), Get(ind, s, e, mid, r, rc)); } int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>n>>k; for(ll i=1;i<=n;i++) { cin>>A[i]; comp.pb(A[i]); comp.pb(A[i]+k); } sort(all(comp)); comp.resize(unique(all(comp))-comp.begin()); N=SZ(comp); for(ll i=1;i<=n;i++) { Upd(0, GI(A[i]), max(Get(0, 0, GI(A[i])), Get(1, 0, GI(A[i]+k)))+1); Upd(1, GI(A[i]), Get(1, 0, GI(A[i]))+1); } cout<<max(Get(0, 0, N), Get(1, 0, N))<<"\n"; }
#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...