답안 #282786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
282786 2020-08-24T22:48:00 Z doowey Global Warming (CEOI18_glo) C++14
0 / 100
5 ms 5248 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const ll inf = (ll)1e10;
const int N = (int)2e5 + 10;
vector<pii> qq[N];

int main(){
    fastIO;
    freopen("in.txt", "r", stdin);
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> v(n);
    for(int i = 0 ; i < n; i ++ ){
        cin >> v[i];
    }
    vector<ll> q;
    ll c;
    int id;
    int res = 0;
    for(int i = 0 ; i < n; i ++ ){
        c = v[i] - x;
        id = lower_bound(q.begin(), q.end(), c) - q.begin();
        if(id == q.size()){
            q.push_back(c);
        }
        else{
            q[id] = c;
        }
        qq[i+1].push_back(mp(c, id+1));
        res = max(res, id + 1);
    }
    vector<ll> g = {};
    int l, r, mid;
    for(int i = n - 1; i >= 0; i -- ){
        l = 0, r = g.size();
        while(l < r){
            mid = (l + r) / 2;
            if(g[mid] > v[i]){
                l = mid + 1;
            }
            else{
                r = mid;
            }
        }
        if(l == g.size()){
            g.push_back(v[i]);
        }
        else{
            g[l] = v[i];
        }
        for(auto x : qq[i]){
            l = 0, r = g.size();
            while(l + 1 < r){
                mid = (l + r) / 2;
                if(g[mid] > x.fi)
                    l = mid;
                else
                    r = mid;
            }
            res = max(res, l + (g[l]>x.fi) + x.se);
        }
    }
    cout << res << "\n";
    return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:34:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         if(id == q.size()){
      |            ~~~^~~~~~~~~~~
glo.cpp:56:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         if(l == g.size()){
      |            ~~^~~~~~~~~~~
glo.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   19 |     freopen("in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 5120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 5120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 5120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 5120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 5120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 5248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 5120 KB Output isn't correct
2 Halted 0 ms 0 KB -