제출 #313939

#제출 시각아이디문제언어결과실행 시간메모리
313939BeanZGlobal Warming (CEOI18_glo)C++14
100 / 100
57 ms6512 KiB
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 2e5 + 5;
ll dp[N], a[N];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("A.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll n, x;
    cin >> n >> x;
    for (int i = 1; i <= n; i++) cin >> a[i];
    vector<ll> val;
    ll ans = 0;
    for (int i = n; i >= 1; i--){
        ll l = 0, h = val.size() - 1;
        while (l <= h){
            ll mid = (l + h) >> 1;
            if (val[mid] > a[i]) l = mid + 1;
            else h = mid - 1;
        }
        if (l == val.size()) val.push_back(a[i]);
        else {
            val[l] = max(val[l], a[i]);
        }
        dp[i] = l + 1;
        ans = max(ans, dp[i]);
    }
    val.clear();
    for (int i = 1; i <= n; i++){
        ll l = 0, h = val.size() - 1;
        while (l <= h){
            ll mid = (l + h) >> 1;
            if (val[mid] < a[i]) l = mid + 1;
            else h = mid - 1;
        }
        if (l == val.size()) val.push_back(a[i]);
        else {
            val[l] = min(val[l], a[i]);
        }
        ans = max(ans, (ll)val.size());
        if (i == n) continue;
        l = 0, h = val.size() - 1;
        while (l <= h){
            ll mid = (l + h) >> 1;
            if (val[mid] >= (a[i + 1] + x)){
                h = mid - 1;
            } else l = mid + 1;
        }
        ans = max(ans, h + 1 + dp[i + 1]);
    }
    cout << ans;
}
/*
*/

컴파일 시 표준 에러 (stderr) 메시지

glo.cpp: In function 'int main()':
glo.cpp:27:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         if (l == val.size()) val.push_back(a[i]);
      |             ~~^~~~~~~~~~~~~
glo.cpp:42:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         if (l == val.size()) val.push_back(a[i]);
      |             ~~^~~~~~~~~~~~~
glo.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   12 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   13 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...