답안 #282787

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
282787 2020-08-24T22:48:15 Z doowey Global Warming (CEOI18_glo) C++14
100 / 100
86 ms 17132 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;
    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:33:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         if(id == q.size()){
      |            ~~~^~~~~~~~~~~
glo.cpp:55:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         if(l == g.size()){
      |            ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 4 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 4 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 3 ms 4992 KB Output is correct
13 Correct 3 ms 4992 KB Output is correct
14 Correct 3 ms 4992 KB Output is correct
15 Correct 3 ms 4992 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 3 ms 4992 KB Output is correct
18 Correct 3 ms 4992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 4 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 3 ms 4992 KB Output is correct
13 Correct 3 ms 4992 KB Output is correct
14 Correct 3 ms 4992 KB Output is correct
15 Correct 3 ms 4992 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 3 ms 4992 KB Output is correct
18 Correct 3 ms 4992 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 4 ms 5120 KB Output is correct
21 Correct 4 ms 5120 KB Output is correct
22 Correct 4 ms 5120 KB Output is correct
23 Correct 4 ms 5120 KB Output is correct
24 Correct 4 ms 5120 KB Output is correct
25 Correct 4 ms 5120 KB Output is correct
26 Correct 4 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 12920 KB Output is correct
2 Correct 76 ms 12920 KB Output is correct
3 Correct 75 ms 12920 KB Output is correct
4 Correct 74 ms 12924 KB Output is correct
5 Correct 53 ms 15212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 7040 KB Output is correct
2 Correct 20 ms 7168 KB Output is correct
3 Correct 20 ms 7040 KB Output is correct
4 Correct 16 ms 7648 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 16 ms 7676 KB Output is correct
7 Correct 18 ms 7040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 8960 KB Output is correct
2 Correct 36 ms 8952 KB Output is correct
3 Correct 65 ms 12920 KB Output is correct
4 Correct 57 ms 15212 KB Output is correct
5 Correct 28 ms 10096 KB Output is correct
6 Correct 46 ms 14700 KB Output is correct
7 Correct 50 ms 14700 KB Output is correct
8 Correct 30 ms 8960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 4 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 3 ms 4992 KB Output is correct
13 Correct 3 ms 4992 KB Output is correct
14 Correct 3 ms 4992 KB Output is correct
15 Correct 3 ms 4992 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 3 ms 4992 KB Output is correct
18 Correct 3 ms 4992 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 4 ms 5120 KB Output is correct
21 Correct 4 ms 5120 KB Output is correct
22 Correct 4 ms 5120 KB Output is correct
23 Correct 4 ms 5120 KB Output is correct
24 Correct 4 ms 5120 KB Output is correct
25 Correct 4 ms 5120 KB Output is correct
26 Correct 4 ms 5120 KB Output is correct
27 Correct 77 ms 12920 KB Output is correct
28 Correct 76 ms 12920 KB Output is correct
29 Correct 75 ms 12920 KB Output is correct
30 Correct 74 ms 12924 KB Output is correct
31 Correct 53 ms 15212 KB Output is correct
32 Correct 20 ms 7040 KB Output is correct
33 Correct 20 ms 7168 KB Output is correct
34 Correct 20 ms 7040 KB Output is correct
35 Correct 16 ms 7648 KB Output is correct
36 Correct 4 ms 4992 KB Output is correct
37 Correct 16 ms 7676 KB Output is correct
38 Correct 18 ms 7040 KB Output is correct
39 Correct 34 ms 8960 KB Output is correct
40 Correct 36 ms 8952 KB Output is correct
41 Correct 65 ms 12920 KB Output is correct
42 Correct 57 ms 15212 KB Output is correct
43 Correct 28 ms 10096 KB Output is correct
44 Correct 46 ms 14700 KB Output is correct
45 Correct 50 ms 14700 KB Output is correct
46 Correct 30 ms 8960 KB Output is correct
47 Correct 39 ms 9976 KB Output is correct
48 Correct 39 ms 9976 KB Output is correct
49 Correct 86 ms 14840 KB Output is correct
50 Correct 56 ms 16384 KB Output is correct
51 Correct 43 ms 14060 KB Output is correct
52 Correct 58 ms 16492 KB Output is correct
53 Correct 49 ms 16492 KB Output is correct
54 Correct 53 ms 17132 KB Output is correct
55 Correct 65 ms 14968 KB Output is correct