Submission #1017440

#TimeUsernameProblemLanguageResultExecution timeMemory
1017440NguyenPhucThangGlobal Warming (CEOI18_glo)C++14
100 / 100
247 ms15040 KiB
#include <bits/stdc++.h> #define forr(i, a, b) for (int i = a; i <= b; i++) #define ford(i, a, b) for (int i = a; i >= b; i--) #define fi first #define se second #define pb push_back #define all(v) v.begin(), v.end() #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vii vector<pii> #define file "test" using namespace std; const int base = 31; const ll mod = 1e9 + 7; const ll oo = 1e18; const int N = 2e5 + 5; const int V = 4e5; int n, x, a[N], t[N], r[N], l[N], st[4*V + 5]; vector<ll> nen; void update(int id, int l, int r, int i, int v){ if (i < l || r < i) return; if (l == r){ st[id] = max(st[id], v); return; } int mid = (l + r) >> 1; update(2 * id, l, mid, i, v), update(2 * id + 1, mid + 1, r, i, v); st[id] = max(st[2 * id], st[2 * id + 1]); } int get(int id, int l, int r, int u, int v){ if (v < l || r < u) return 0; if (u <= l && r <= v) return st[id]; int mid = (l + r) >> 1; return max(get(2 * id, l, mid, u, v), get(2 * id + 1, mid + 1, r, u, v)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> x; forr(i, 1, n) { cin >> a[i]; t[i] = a[i] - x; nen.pb(a[i]); nen.pb(t[i]); } sort(all(nen)); nen.resize(unique(all(nen)) - nen.begin()); forr(i,1,n) { a[i] = lower_bound(all(nen), a[i]) - nen.begin() + 1; t[i] = lower_bound(all(nen), t[i]) - nen.begin() + 1; } ford(i, n, 1){ r[i] = get(1, 1, V, t[i] + 1, V) + 1; update(1, 1, V, a[i], get(1, 1, V, a[i] + 1, V) + 1); } memset(st, 0, sizeof st); forr(i, 1, n){ l[i] = get(1, 1, V, 1, t[i] - 1) + 1; update(1, 1, V, t[i], l[i]); } int res = 0; forr(i, 1, n) res = max(res, l[i] + r[i] - 1); cout << res; 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...