제출 #1013689

#제출 시각아이디문제언어결과실행 시간메모리
1013689ThunnusGlobal Warming (CEOI18_glo)C++17
100 / 100
40 ms7956 KiB
#include<bits/stdc++.h> using namespace std; using i64 = long long; #define int i64 #define vi vector<int> #define vvi vector<vi> #define vb vector<bool> #define pii pair<int, int> #define fi first #define se second #define sz(x) (int)(x).size() signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, x, ans = 0; cin >> n >> x; vi a(n); for(int &i : a) cin >> i; // longest increasing subsequence ending at i vi lis, at_lis(n); for(int i = 0; i < n; i++){ int pos = lower_bound(lis.begin(), lis.end(), a[i]) - lis.begin(); if(pos == sz(lis)) lis.emplace_back(a[i]); else lis[pos] = a[i]; at_lis[i] = pos + 1; } // longest decreasing subsequence ending at i of reverse // = longest increasing subsequence starting at i lis = vi(n, INT32_MAX); for(int i = n - 1; i >= 0; i--){ int pos = lower_bound(lis.begin(), lis.end(), -a[i] + x) - lis.begin(); /*if(at_lis[i] + pos > ans) cout << "i: " << i << " val: " << at_lis[i] + pos << "\n";*/ ans = max(ans, at_lis[i] + pos); int insert_pos = lower_bound(lis.begin(), lis.end(), -a[i]) - lis.begin(); lis[insert_pos] = -a[i]; } cout << ans; 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...