Submission #574356

#TimeUsernameProblemLanguageResultExecution timeMemory
574356tamthegodGlobal Warming (CEOI18_glo)C++14
100 / 100
550 ms47704 KiB
#include<iostream> #include<iomanip> #include<algorithm> #include<stack> #include<queue> #include<string> #include<string.h> #include<cmath> #include<vector> #include<map> #include<unordered_map> #include<set> #include<unordered_set> #include<cstdio> #include<bitset> #include<chrono> #include<random> #include<ext/rope> /* ordered_set #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> */ #define int long long #define pb push_back #define fi first #define se second using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxN = 1e6 + 5; const int mod = 1e9 + 7; const ll oo = 1e18; int n, x, a[maxN]; int b[maxN]; int f[maxN], e[maxN]; int dp[maxN]; int st[4 * maxN]; void update(int id, int l, int r, int pos, int val) { if(l > pos || r < pos) return; if(l == r && l == pos) { st[id] = val; return; } int mid = (l + r) / 2; update(id * 2, l, mid, pos, val); update(id * 2 + 1, mid + 1, r, pos, val); st[id] = min(st[id * 2], st[id * 2 + 1]); } int get(int id, int l, int r, int u, int v) { if(l > v || r < u) return oo; if(l >= u && r <= v) return st[id]; int mid = (l + r) / 2; return min(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v)); } void ReadInput() { cin >> n >> x; for(int i=1; i<=n; i++) cin >> a[i]; } void Solve() { for(int i=1; i<=n; i++) b[i] = -a[i]; memset(e, 3, sizeof e); for(int i=n; i>=1; i--) { int j = lower_bound(e + 1, e + n + 1, b[i]) - e; dp[i] = j; e[dp[i]] = b[i]; } memset(e, 3, sizeof e); for(int i=1; i<=n; i++) { int j = lower_bound(e + 1, e + n + 1, a[i]) - e; f[i] = j; e[f[i]] = a[i]; } memset(st, 3, sizeof st); int res = 0; for(int i=1; i<=n; i++) { int tmp = a[i] + x - 1; int low = 1, high = n, mid; while(low <= high) { mid = (low + high) / 2; if(get(1, 1, n, mid, n) <= tmp) low = mid + 1; else high = mid - 1; } res = max(res, dp[i] + high); update(1, 1, n, f[i], a[i]); } cout << res << '\n'; } int32_t main() { //freopen("x.inp", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(nullptr); ReadInput(); Solve(); }
#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...