Submission #930615

# Submission time Handle Problem Language Result Execution time Memory
930615 2024-02-20T08:07:29 Z Sam86_b Global Warming (CEOI18_glo) C++17
100 / 100
137 ms 6132 KB
#include <bits/stdc++.h>
using namespace std;
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<'\n'
#define dbgv(v) cout<<#v<<" = "; for(auto x : v) cout<<x<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) #x<<'='<<(x)<<' '
#define sep cout<<"---------------"<<endl
#define kill(x) {cout<<x<<'\n'; return;}
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define sz(x) int(x.size())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

const int N = 2e5+5;
int n, x, a[N], b[N], lis_pre[N], lis_suf[N], fen[2][N];
vector<int> temp;

void add(int l, int x, int t){
    while(l <= sz(temp)) maxm(fen[t][l], x), l += (l & -l);
}
int get(int r, int t){
    int res = 0;
    while(r <= sz(temp) and r > 0) maxm(res, fen[t][r]), r -= (r & -r);
    return res;
}

void Solve(){
    cin >> n >> x;
    f(i, 0, n) cin >> a[i], temp.pb(a[i]), b[i] = a[i];
    sort(all(temp));
    temp.resize(unique(all(temp)) - temp.begin());
    f(i, 0, n) a[i] = lower_bound(all(temp), a[i]) - temp.begin() + 1;
    f(i, 0, n) lis_pre[i] = get(a[i]-1, 0) + 1, add(a[i], lis_pre[i], 0);
    f_(i, n-1, 0){
        int t1 = a[i] + 1;
        lis_suf[i] = get(sz(temp) + 1 - t1, 1) + 1, add(sz(temp) + 1 - a[i], lis_suf[i], 1);
    }
    int ans = 0;
    f(i, 1, sz(temp)+1) fen[0][i] = fen[1][i] = 0;
    f_(i, n-1, 0){
        int t1 = b[i] - x;
        int p = upper_bound(all(temp), t1) - temp.begin() + 1;
        if(p <= n) maxm(ans, lis_pre[i] + get(sz(temp) + 1 - p, 1));
        add(sz(temp) + 1 - a[i], lis_suf[i], 1);
    }
    f(i, 0, n){
        int t1 = b[i] + x;
        int p = lower_bound(all(temp), t1) - temp.begin();
        if(p) maxm(ans, lis_suf[i] + get(p, 0));
        add(a[i], lis_pre[i], 0);
    }
    cout<<ans<<'\n';
}

int main(){
    ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int tt;
    //cin >> tt;

    tt = 1;
    while(tt--){
        Solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 137 ms 6020 KB Output is correct
2 Correct 131 ms 5896 KB Output is correct
3 Correct 131 ms 6132 KB Output is correct
4 Correct 131 ms 5884 KB Output is correct
5 Correct 65 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3292 KB Output is correct
2 Correct 28 ms 3296 KB Output is correct
3 Correct 28 ms 3296 KB Output is correct
4 Correct 14 ms 3040 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 15 ms 3112 KB Output is correct
7 Correct 23 ms 3296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 4204 KB Output is correct
2 Correct 39 ms 4096 KB Output is correct
3 Correct 86 ms 5840 KB Output is correct
4 Correct 52 ms 5064 KB Output is correct
5 Correct 26 ms 4056 KB Output is correct
6 Correct 47 ms 5848 KB Output is correct
7 Correct 51 ms 5824 KB Output is correct
8 Correct 37 ms 4096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 137 ms 6020 KB Output is correct
28 Correct 131 ms 5896 KB Output is correct
29 Correct 131 ms 6132 KB Output is correct
30 Correct 131 ms 5884 KB Output is correct
31 Correct 65 ms 5072 KB Output is correct
32 Correct 27 ms 3292 KB Output is correct
33 Correct 28 ms 3296 KB Output is correct
34 Correct 28 ms 3296 KB Output is correct
35 Correct 14 ms 3040 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 15 ms 3112 KB Output is correct
38 Correct 23 ms 3296 KB Output is correct
39 Correct 41 ms 4204 KB Output is correct
40 Correct 39 ms 4096 KB Output is correct
41 Correct 86 ms 5840 KB Output is correct
42 Correct 52 ms 5064 KB Output is correct
43 Correct 26 ms 4056 KB Output is correct
44 Correct 47 ms 5848 KB Output is correct
45 Correct 51 ms 5824 KB Output is correct
46 Correct 37 ms 4096 KB Output is correct
47 Correct 60 ms 4048 KB Output is correct
48 Correct 59 ms 4048 KB Output is correct
49 Correct 129 ms 5896 KB Output is correct
50 Correct 59 ms 5072 KB Output is correct
51 Correct 48 ms 4812 KB Output is correct
52 Correct 75 ms 5880 KB Output is correct
53 Correct 51 ms 5840 KB Output is correct
54 Correct 52 ms 5948 KB Output is correct
55 Correct 103 ms 5884 KB Output is correct