제출 #530348

#제출 시각아이디문제언어결과실행 시간메모리
530348abc864197532Global Warming (CEOI18_glo)C++17
25 / 100
2033 ms16848 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define mp make_pair #define pb push_back #define eb emplace_back #define X first #define Y second #define pii pair<int,int> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() void abc() {cout << endl;} template <typename T, typename ...U> void abc(T i, U ...j) { cout << i << ' ', abc(j...); } template <typename T> void printv(T l, T r) { for (; l != r; ++l) cout << *l << " \n"[l + 1 == r]; } #ifdef Doludu #define test(x...) abc("[" + string(#x) + "]", x); #define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #else #define test(x...) void(0); #define owo ios::sync_with_stdio(false), cin.tie(0) #endif const int N = 400087; struct BIT { int val[N]; void init() { fill(val, val + N, 0); } void add(int p, int v) { p += 5; for (int i = p; i < N; i += i & (-i)) val[i] = max(val[i], v); } int query(int p) { p += 5; int ans = 0; for (int i = p; i > 0; i -= i & (-i)) ans = max(ans, val[i]); return ans; } } bit1, bit2; vector <int> a; int n; int ask(int x) { vector <vector <int>> dp(n, vector <int> (3, 0)); vector <int> v; for (int i : a) v.pb(i), v.pb(i + x); sort(all(v)), v.resize(unique(all(v)) - v.begin()); bit1.init(), bit2.init(); dp[0][0] = 1, dp[0][1] = 1, dp[0][2] = 0; int ans = 1; for (int i = 0; i < n; ++i) { int p = lower_bound(all(v), a[i]) - v.begin(); int q = lower_bound(all(v), a[i] + x) - v.begin(); if (i) { dp[i][0] = bit1.query(p) + 1; dp[i][1] = max(bit1.query(q), bit2.query(q)) + 1; dp[i][2] = bit2.query(p) + 1; } bit1.add(p + 1, dp[i][0]); bit2.add(q + 1, dp[i][1]); ans = max({ans, dp[i][0], dp[i][1], dp[i][2]}); } return ans; } int main () { owo; int d; cin >> n >> d; a.resize(n); for (int i = 0; i < n; ++i) cin >> a[i]; lli l = -d, r = d + 1; while (r - l > 5) { lli m1 = (l + l + r) / 3, m2 = (l + r + r) / 3; if (ask(m1) < ask(m2)) l = m1; else r = m2; } int ans = 0; for (int i = l; i < r; ++i) ans = max(ans, ask(i)); cout << ans << endl; }
#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...