Submission #885410

# Submission time Handle Problem Language Result Execution time Memory
885410 2023-12-09T15:24:33 Z ByeWorld Global Warming (CEOI18_glo) C++14
100 / 100
268 ms 26932 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#define bupol __builtin_popcount
#define int long long 
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
const int MAXN = 3e5+20;
const int LOG = 60;
const int MOD = 998244353;
const int SQRT = 520;
const int INF = 1e18;
typedef pair<int,int> pii;
typedef pair<pii,int> ipii;
 
int n, x;
int a[MAXN], add[MAXN];
vector <int> vec;

struct seg {
    int st[4*MAXN];
    int que(int id, int l, int r, int x, int y){
        if(x<=l && r<=y) return st[id];
        if(r<x || y<l) return -INF;
        return max(que(lf, l, md, x, y), que(rg, md+1, r, x, y));
    }
    int upd(int id, int l, int r, int x, int y){
        if(l==r && r==x) return st[id] = max(st[id], y);
        if(r<x || x<l) return st[id];
        return st[id] = max(upd(lf, l, md, x, y), upd(rg, md+1, r, x, y));
    }
} A, B;
 
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> x;
    vector <int> cor;
    for(int i=1; i<=n; i++){
        cin >> a[i];
        cor.pb(a[i]); cor.pb(a[i]+x);
    }
    //for(int i=0; i<=4*n; i++) st[i] = -INF;
    cor.pb(-INF);
    sort(cor.begin(), cor.end());
    cor.resize(unique(cor.begin(), cor.end()) - cor.begin());
    for(int i=1; i<=n; i++){
        int te = a[i];
        a[i] = lower_bound(cor.begin(), cor.end(), a[i]) - cor.begin();
        add[i] = lower_bound(cor.begin(), cor.end(), te+x) - cor.begin();
        //cout << i << ' ' << a[i] << ' ' << add[i] << " i\n";
    }

    int ans = 0;
    for(int i=1; i<=n; i++){
        int num = A.que(1, 1, 2*n, 1, a[i]-1);
        int num2 = A.que(1, 1, 2*n, 1, add[i]-1);
        int pre = B.que(1, 1, 2*n, 1, add[i]-1);

        A.upd(1, 1, 2*n, a[i], max(0ll, num)+1);
        B.upd(1, 1, 2*n, add[i], max(0ll, max(num2, pre))+1);
        ans = max(ans, max(max(num2, pre), max(num, 0ll))+1 );
    }
    //for(int i=1; i<=n; i++) cout << pr[i] << " \n"[i==n];
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 2 ms 4576 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4572 KB Output is correct
23 Correct 1 ms 4696 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 2 ms 4440 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 16636 KB Output is correct
2 Correct 207 ms 16032 KB Output is correct
3 Correct 250 ms 16064 KB Output is correct
4 Correct 204 ms 16056 KB Output is correct
5 Correct 97 ms 11964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 9432 KB Output is correct
2 Correct 53 ms 9432 KB Output is correct
3 Correct 50 ms 9428 KB Output is correct
4 Correct 25 ms 7376 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 32 ms 7896 KB Output is correct
7 Correct 40 ms 9316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 10440 KB Output is correct
2 Correct 102 ms 10440 KB Output is correct
3 Correct 260 ms 16064 KB Output is correct
4 Correct 102 ms 11968 KB Output is correct
5 Correct 64 ms 10440 KB Output is correct
6 Correct 112 ms 15808 KB Output is correct
7 Correct 122 ms 16576 KB Output is correct
8 Correct 84 ms 10436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 2 ms 4576 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4572 KB Output is correct
23 Correct 1 ms 4696 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 2 ms 4440 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 211 ms 16636 KB Output is correct
28 Correct 207 ms 16032 KB Output is correct
29 Correct 250 ms 16064 KB Output is correct
30 Correct 204 ms 16056 KB Output is correct
31 Correct 97 ms 11964 KB Output is correct
32 Correct 48 ms 9432 KB Output is correct
33 Correct 53 ms 9432 KB Output is correct
34 Correct 50 ms 9428 KB Output is correct
35 Correct 25 ms 7376 KB Output is correct
36 Correct 1 ms 4440 KB Output is correct
37 Correct 32 ms 7896 KB Output is correct
38 Correct 40 ms 9316 KB Output is correct
39 Correct 103 ms 10440 KB Output is correct
40 Correct 102 ms 10440 KB Output is correct
41 Correct 260 ms 16064 KB Output is correct
42 Correct 102 ms 11968 KB Output is correct
43 Correct 64 ms 10440 KB Output is correct
44 Correct 112 ms 15808 KB Output is correct
45 Correct 122 ms 16576 KB Output is correct
46 Correct 84 ms 10436 KB Output is correct
47 Correct 113 ms 15304 KB Output is correct
48 Correct 104 ms 15308 KB Output is correct
49 Correct 268 ms 26932 KB Output is correct
50 Correct 106 ms 17164 KB Output is correct
51 Correct 95 ms 15264 KB Output is correct
52 Correct 151 ms 17700 KB Output is correct
53 Correct 118 ms 17172 KB Output is correct
54 Correct 123 ms 18300 KB Output is correct
55 Correct 189 ms 23352 KB Output is correct