제출 #884529

#제출 시각아이디문제언어결과실행 시간메모리
884529ByeWorldGlobal Warming (CEOI18_glo)C++14
17 / 100
38 ms9432 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#define bupol __builtin_popcount
#define int long long 
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
const int MAXN = 3e5+20;
const int LOG = 60;
const int MOD = 998244353;
const int SQRT = 520;
const int INF = 1e18;
typedef pair<int,int> pii;
typedef pair<pii,int> ipii;

int n, x;
int a[MAXN], pr[MAXN], su[MAXN];
vector <int> vec;

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> x;
    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=1; i<=n; i++){
        auto it = lower_bound(vec.begin(), vec.end(), a[i]);
        if(it == vec.end()){
            vec.pb(a[i]);
        } else {
            int id = it - vec.begin();
            vec[id] = a[i];
        }
        pr[i] = vec.size();
    }
    vec.clear();
    for(int i=n; i>=1; i--){
        auto it = lower_bound(vec.begin(), vec.end(), -a[i]);
        if(it == vec.end()){
            vec.pb(-a[i]);
        } else {
            int id = it - vec.begin();
            vec[id] = -a[i];
        }
        su[i] = vec.size();
    }
    int ans = 0;
    for(int i=1; i<=n-1; i++) ans = max(ans, pr[i]+su[i+1]);
    cout << ans << '\n';
}
#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...