Submission #953436

# Submission time Handle Problem Language Result Execution time Memory
953436 2024-03-26T01:18:35 Z Rifal Global Warming (CEOI18_glo) C++14
100 / 100
1809 ms 89684 KB
#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 1000000007
#define INF 1000000000
#define INF2 2000000000
///#define cin fin
///#define cout fout
using namespace std;
double const EPS = 1e-14;
typedef long long ll;
///ofstream fout("herding.out");
///ifstream fin("herding.in");
const int M = 6e5 + 3;
const int N = 6e5 + 5;
ll seg[N*4];
map<ll,int> mp;
void Build(int x, int l, int r) {
    if(l == r) {
        seg[x] = 0;
    }
    else {
        int mid = (l+r)/2;
        Build(x*2,l,mid); Build(x*2+1,mid+1,r);
        seg[x] = 0;
    }
}
void Update(int x, int l, int r, int pos, ll val) {
    if(l == r) {
        seg[x] = max(seg[x],val);
    }
    else {
        int mid = (l+r)/2;
        if(pos <= mid) Update(x*2,l,mid,pos,val);
        else Update(x*2+1,mid+1,r,pos,val);
        seg[x] = max(seg[x*2],seg[x*2+1]);
    }
}
ll sol(int x, int l, int r, int L, int R) {
    if(l > R || r < L) {
        return 0;
    }
    else if(l >= L && r <= R) {
        return seg[x];
    }
    else {
        int mid = (l+r)/2;
        return max(sol(x*2,l,mid,L,R),sol(x*2+1,mid+1,r,L,R));
    }
}
int main()
{
    ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    int n; ll x; cin >> n >> x; ll arr[n+1] = {};
    set<ll> st;
    for(int i = 1; i <= n; i++){
        cin >> arr[i];
        st.insert(arr[i]);
        st.insert(arr[i]-x);
        st.insert(arr[i]+x);
    }
    ll dp1[n+1] = {}, dp2[n+1] = {};
    int cnt = 1;
    for(auto i : st) {
        mp[i] = cnt; cnt++; }
    for(int i = 1; i <= n; i++) {
        int cur = mp[arr[i]];
        ll mx = sol(1,1,M,1,cur-1);
        dp1[i] = max(dp1[i],mx+1);
        Update(1,1,M,cur,dp1[i]);
    }
    Build(1,1,M);
    for(int i = n; i >= 1; i--) {
        int cur = mp[arr[i]];
        ll mx = sol(1,1,M,cur+1,M);
        dp2[i] = max(dp2[i],mx+1);
        Update(1,1,M,cur,dp2[i]);
    }
    Build(1,1,M);
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        int cur = mp[arr[i]+x];
        int cur2 = mp[arr[i]];
        ll mx = sol(1,1,M,1,cur-1);
        ans = max(ans,dp2[i]+mx);
        Update(1,1,M,cur2,dp1[i]);
    }
    Build(1,1,M);
    for(int i = n; i >= 1; i--) {
        int cur = mp[arr[i]-x];
        int cur2 = mp[arr[i]];
        ll mx = sol(1,1,M,cur+1,M);
        ans = max(ans,mx+dp1[i]);
        Update(1,1,M,cur2,dp2[i]);
    }
    cout << ans << endl;
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 10 ms 17048 KB Output is correct
2 Correct 11 ms 16988 KB Output is correct
3 Correct 9 ms 17236 KB Output is correct
4 Correct 8 ms 16988 KB Output is correct
5 Correct 8 ms 16988 KB Output is correct
6 Correct 9 ms 16988 KB Output is correct
7 Correct 8 ms 16988 KB Output is correct
8 Correct 8 ms 16940 KB Output is correct
9 Correct 9 ms 16988 KB Output is correct
10 Correct 9 ms 16988 KB Output is correct
11 Correct 8 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 17048 KB Output is correct
2 Correct 11 ms 16988 KB Output is correct
3 Correct 9 ms 17236 KB Output is correct
4 Correct 8 ms 16988 KB Output is correct
5 Correct 8 ms 16988 KB Output is correct
6 Correct 9 ms 16988 KB Output is correct
7 Correct 8 ms 16988 KB Output is correct
8 Correct 8 ms 16940 KB Output is correct
9 Correct 9 ms 16988 KB Output is correct
10 Correct 9 ms 16988 KB Output is correct
11 Correct 8 ms 16988 KB Output is correct
12 Correct 8 ms 16984 KB Output is correct
13 Correct 9 ms 16988 KB Output is correct
14 Correct 9 ms 16948 KB Output is correct
15 Correct 9 ms 16984 KB Output is correct
16 Correct 8 ms 16852 KB Output is correct
17 Correct 13 ms 16988 KB Output is correct
18 Correct 9 ms 16852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 17048 KB Output is correct
2 Correct 11 ms 16988 KB Output is correct
3 Correct 9 ms 17236 KB Output is correct
4 Correct 8 ms 16988 KB Output is correct
5 Correct 8 ms 16988 KB Output is correct
6 Correct 9 ms 16988 KB Output is correct
7 Correct 8 ms 16988 KB Output is correct
8 Correct 8 ms 16940 KB Output is correct
9 Correct 9 ms 16988 KB Output is correct
10 Correct 9 ms 16988 KB Output is correct
11 Correct 8 ms 16988 KB Output is correct
12 Correct 8 ms 16984 KB Output is correct
13 Correct 9 ms 16988 KB Output is correct
14 Correct 9 ms 16948 KB Output is correct
15 Correct 9 ms 16984 KB Output is correct
16 Correct 8 ms 16852 KB Output is correct
17 Correct 13 ms 16988 KB Output is correct
18 Correct 9 ms 16852 KB Output is correct
19 Correct 12 ms 17244 KB Output is correct
20 Correct 10 ms 17244 KB Output is correct
21 Correct 11 ms 17244 KB Output is correct
22 Correct 11 ms 17064 KB Output is correct
23 Correct 10 ms 17236 KB Output is correct
24 Correct 10 ms 17244 KB Output is correct
25 Correct 10 ms 16988 KB Output is correct
26 Correct 10 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 943 ms 43632 KB Output is correct
2 Correct 846 ms 45560 KB Output is correct
3 Correct 871 ms 45740 KB Output is correct
4 Correct 943 ms 45652 KB Output is correct
5 Correct 326 ms 33836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 237 ms 34640 KB Output is correct
2 Correct 221 ms 35104 KB Output is correct
3 Correct 244 ms 35116 KB Output is correct
4 Correct 104 ms 26704 KB Output is correct
5 Correct 8 ms 16988 KB Output is correct
6 Correct 98 ms 23968 KB Output is correct
7 Correct 155 ms 31316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 556 ms 52160 KB Output is correct
2 Correct 592 ms 53108 KB Output is correct
3 Correct 1678 ms 89412 KB Output is correct
4 Correct 457 ms 55612 KB Output is correct
5 Correct 326 ms 52628 KB Output is correct
6 Correct 626 ms 85332 KB Output is correct
7 Correct 578 ms 85808 KB Output is correct
8 Correct 403 ms 53332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 17048 KB Output is correct
2 Correct 11 ms 16988 KB Output is correct
3 Correct 9 ms 17236 KB Output is correct
4 Correct 8 ms 16988 KB Output is correct
5 Correct 8 ms 16988 KB Output is correct
6 Correct 9 ms 16988 KB Output is correct
7 Correct 8 ms 16988 KB Output is correct
8 Correct 8 ms 16940 KB Output is correct
9 Correct 9 ms 16988 KB Output is correct
10 Correct 9 ms 16988 KB Output is correct
11 Correct 8 ms 16988 KB Output is correct
12 Correct 8 ms 16984 KB Output is correct
13 Correct 9 ms 16988 KB Output is correct
14 Correct 9 ms 16948 KB Output is correct
15 Correct 9 ms 16984 KB Output is correct
16 Correct 8 ms 16852 KB Output is correct
17 Correct 13 ms 16988 KB Output is correct
18 Correct 9 ms 16852 KB Output is correct
19 Correct 12 ms 17244 KB Output is correct
20 Correct 10 ms 17244 KB Output is correct
21 Correct 11 ms 17244 KB Output is correct
22 Correct 11 ms 17064 KB Output is correct
23 Correct 10 ms 17236 KB Output is correct
24 Correct 10 ms 17244 KB Output is correct
25 Correct 10 ms 16988 KB Output is correct
26 Correct 10 ms 16988 KB Output is correct
27 Correct 943 ms 43632 KB Output is correct
28 Correct 846 ms 45560 KB Output is correct
29 Correct 871 ms 45740 KB Output is correct
30 Correct 943 ms 45652 KB Output is correct
31 Correct 326 ms 33836 KB Output is correct
32 Correct 237 ms 34640 KB Output is correct
33 Correct 221 ms 35104 KB Output is correct
34 Correct 244 ms 35116 KB Output is correct
35 Correct 104 ms 26704 KB Output is correct
36 Correct 8 ms 16988 KB Output is correct
37 Correct 98 ms 23968 KB Output is correct
38 Correct 155 ms 31316 KB Output is correct
39 Correct 556 ms 52160 KB Output is correct
40 Correct 592 ms 53108 KB Output is correct
41 Correct 1678 ms 89412 KB Output is correct
42 Correct 457 ms 55612 KB Output is correct
43 Correct 326 ms 52628 KB Output is correct
44 Correct 626 ms 85332 KB Output is correct
45 Correct 578 ms 85808 KB Output is correct
46 Correct 403 ms 53332 KB Output is correct
47 Correct 631 ms 53212 KB Output is correct
48 Correct 640 ms 53252 KB Output is correct
49 Correct 1809 ms 89168 KB Output is correct
50 Correct 433 ms 55748 KB Output is correct
51 Correct 348 ms 43348 KB Output is correct
52 Correct 443 ms 44904 KB Output is correct
53 Correct 581 ms 88792 KB Output is correct
54 Correct 627 ms 89684 KB Output is correct
55 Correct 853 ms 74832 KB Output is correct