# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
246340 | Sorting | Global Warming (CEOI18_glo) | C++14 | 2070 ms | 3052 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int k_N = 2e5 + 3;
const int k_Inf = 1e9 + 3;
int n, x;
int t[k_N];
int ans[k_N];
int get_lis(){
vector<int> dp;
dp.push_back({-k_Inf});
for(int i = 0; i < n; ++i){
auto it = lower_bound(dp.begin(), dp.end(), t[i]);
if(it == dp.end())
dp.push_back(t[i]);
else
dp[it - dp.begin()] = t[i];
ans[i] += dp.size() - 1;
}
return dp.size() - 1;
}
void get_lds(){
vector<int> dp;
dp.push_back({k_Inf});
for(int i = n - 1; i >= 0; --i){
int l = 0, r = dp.size();
while(l != r){
int mid = (l + r) >> 1;
if(t[i] >= dp[mid])
r = mid;
else
l = mid + 1;
}
if(l == dp.size())
dp.push_back(t[i]);
else
dp[l] = t[i];
//cout << dp.size() << "\n";
ans[i - 1] += dp.size() - 1;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> x;
for(int i = 0; i < n; ++i)
cin >> t[i];
if(x == k_Inf - 3){
int answer = 0;
get_lds();
get_lis();
for(int i = 0; i < n; ++i)
answer = max(ans[i], answer);
cout << answer << "\n";
}
else{
int answer = 0;
for(int i = 0; i < n; ++i){
t[i] -= x;
answer = max(get_lis(), answer);
if(x == 0)
break;
}
cout << answer << "\n";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |