Submission #89142

#TimeUsernameProblemLanguageResultExecution timeMemory
89142SpeedOfMagicGlobal Warming (CEOI18_glo)C++17
58 / 100
790 ms263168 KiB
/** MIT License Copyright (c) 2018 Vasilyev Daniil **/ #include <bits/stdc++.h> using namespace std; template<typename T> using v = vector<T>; typedef long long longlong; //#define int longlong typedef long double ld; typedef string str; typedef vector<int> vint; #define rep(a, l, r) for(int a = (l); a < (r); a++) #define pb push_back #define fs first #define sc second #define sz(a) ((int) a.size()) const long long inf = 4611686018427387903; //2^62 - 1 #if 0 //FileIO const string fileName = ""; ifstream fin ((fileName == "" ? "input.txt" : fileName + ".in" )); ofstream fout((fileName == "" ? "output.txt" : fileName + ".out")); #define get fin>> #define put fout<< #else #define get cin>> #define put cout<< #endif #define eol put endl void read() {} template<typename Arg,typename... Args> void read (Arg& arg,Args&... args){get (arg) ;read(args...) ;} void print(){} template<typename Arg,typename... Args> void print(Arg arg,Args... args){put (arg)<<" ";print(args...);} int getInt(){int a; get a; return a;} //code goes here const int N = 262144; int segTree[N * 2]; void update(int p, int val, int cur = 1, int ll = 1, int rr = N) { if (ll == rr) { segTree[cur] = max(segTree[cur], val); return; } int mid = (ll + rr) / 2; if (p <= mid) update(p, val, cur * 2, ll, mid); else update(p, val, cur * 2 + 1, mid + 1, rr); segTree[cur] = max(segTree[cur * 2], segTree[cur * 2 + 1]); } int query(int l, int r, int cur = 1, int ll = 1, int rr = N) { if (l > r) return 0; else if (l == ll && r == rr) return segTree[cur]; else { int mid = (ll + rr) / 2; int res = max(query(l, min(r, mid), cur * 2, ll, mid), query(max(l, mid + 1), r, cur * 2 + 1, mid + 1, rr)); return res; } } void run() { memset(segTree, 0, sizeof segTree); int n, k; read(n, k); int a[n]; set<int> d; rep(i, 0, n) { get a[i]; d.insert(a[i]); d.insert(a[i] - k); } map<int, int> inv; int p = 2; for (int j : d) inv[j] = p++; int v[n]; rep(i, 0, n) v[i] = 1e9 + 1; int dp[n][2]; rep(i, 0, n) { dp[i][0] = (lower_bound(v, v + n, a[i]) - v) + 1; v[dp[i][0] - 1] = a[i]; dp[i][1] = query(1, inv[a[i]] - 1) + 1; update(inv[a[i] - k], dp[i][0]); update(inv[a[i]], dp[i][1]); } int ans = 0; rep(i, 0, n) ans = max(ans, dp[i][1]); put ans; } signed main() {srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); put fixed << setprecision(12); run(); return 0;}
#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...