Submission #877430

# Submission time Handle Problem Language Result Execution time Memory
877430 2023-11-23T08:36:54 Z dead0ne Global Warming (CEOI18_glo) C++17
100 / 100
47 ms 8144 KB
#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define int long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define inf 1000000009
#define MOD 1000000007
#define lim 200005
using namespace std;




void solve(){
    int n,x; cin >> n >> x;
    int arr[n+1], bef[n+1], aft[n+1];
    for(int i=1; i<=n; i++) cin >> arr[i];

    vector<int> lis;
    for(int i=1; i<=n; i++){
        bef[i] = lower_bound(all(lis), arr[i]+x) - lis.begin();
        //cerr << arr[i] spc bef[i] << endl;

        int pos = lower_bound(all(lis), arr[i]) - lis.begin();
        if(pos == lis.size()) lis.pb(arr[i]);
        else lis[pos] = arr[i];
    }
    lis.clear();

    for(int i=n; i>=1; i--){
        int pos = lower_bound(lis.begin(), lis.end(), arr[i], greater<int>()) - lis.begin();
        if(pos == lis.size()) lis.pb(arr[i]);
        else lis[pos] = arr[i];
        aft[i]=pos+1;
    }

    int ans=0;
    for(int i=1; i<=n; i++) ans = max(ans, bef[i]+aft[i]);
    cout << ans << endl;
}



signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    #ifdef Local
    freopen("in","r",stdin);
    freopen("out","w",stdout);
    #endif

    /*freopen("fcolor.in","r",stdin);
    freopen("fcolor.out","w",stdout);*/

    int t=1;
    //cin >> t;
    while(t--) solve();
}

Compilation message

glo.cpp: In function 'void solve()':
glo.cpp:33:16: 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]
   33 |         if(pos == lis.size()) lis.pb(arr[i]);
      |            ~~~~^~~~~~~~~~~~~
glo.cpp:40:16: 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]
   40 |         if(pos == lis.size()) lis.pb(arr[i]);
      |            ~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 6920 KB Output is correct
2 Correct 46 ms 7308 KB Output is correct
3 Correct 45 ms 6996 KB Output is correct
4 Correct 46 ms 7000 KB Output is correct
5 Correct 23 ms 7388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1884 KB Output is correct
2 Correct 11 ms 2000 KB Output is correct
3 Correct 11 ms 1884 KB Output is correct
4 Correct 6 ms 2292 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 5 ms 2140 KB Output is correct
7 Correct 9 ms 1880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3672 KB Output is correct
2 Correct 19 ms 3676 KB Output is correct
3 Correct 38 ms 7088 KB Output is correct
4 Correct 23 ms 7432 KB Output is correct
5 Correct 11 ms 3808 KB Output is correct
6 Correct 22 ms 7196 KB Output is correct
7 Correct 24 ms 7892 KB Output is correct
8 Correct 16 ms 3680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 456 KB Output is correct
27 Correct 46 ms 6920 KB Output is correct
28 Correct 46 ms 7308 KB Output is correct
29 Correct 45 ms 6996 KB Output is correct
30 Correct 46 ms 7000 KB Output is correct
31 Correct 23 ms 7388 KB Output is correct
32 Correct 14 ms 1884 KB Output is correct
33 Correct 11 ms 2000 KB Output is correct
34 Correct 11 ms 1884 KB Output is correct
35 Correct 6 ms 2292 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 5 ms 2140 KB Output is correct
38 Correct 9 ms 1880 KB Output is correct
39 Correct 19 ms 3672 KB Output is correct
40 Correct 19 ms 3676 KB Output is correct
41 Correct 38 ms 7088 KB Output is correct
42 Correct 23 ms 7432 KB Output is correct
43 Correct 11 ms 3808 KB Output is correct
44 Correct 22 ms 7196 KB Output is correct
45 Correct 24 ms 7892 KB Output is correct
46 Correct 16 ms 3680 KB Output is correct
47 Correct 22 ms 3760 KB Output is correct
48 Correct 22 ms 3676 KB Output is correct
49 Correct 47 ms 7068 KB Output is correct
50 Correct 23 ms 7384 KB Output is correct
51 Correct 20 ms 6000 KB Output is correct
52 Correct 23 ms 7380 KB Output is correct
53 Correct 26 ms 7416 KB Output is correct
54 Correct 24 ms 8144 KB Output is correct
55 Correct 37 ms 7000 KB Output is correct