Submission #827893

# Submission time Handle Problem Language Result Execution time Memory
827893 2023-08-16T21:48:52 Z BT21tata Global Warming (CEOI18_glo) C++17
100 / 100
128 ms 9776 KB
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define SPEED ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define rall(v) (v).rbegin(),(v).rend()
#define all(v) (v).begin(),(v).end()
#define setp fixed<<setprecision
#define OK cerr<<"OK"<<endl<<flush
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define F first
#define S second
#define y0 jahdakdh
#define y1 jahsadakdakdh
#define endl '\n'
const ll MOD=1e9+7;
const ll mod=(1ll<<31)-1;
const ld eps=1e-8;
const ll MAXLONG=9223372036854775807;
const ll MINLONG=-9223372036854775807;
using namespace std;
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
const int N=2e5+5;
 
int n, x, a[N], ans, t[N<<2];
vector<pii>v;

vector<int> LIS()
{
    vector<int>v{a[0]}, ret{1};
    for(int i=1; i<n; i++)
    {
        if(v.back()<a[i])
        {
            v.pb(a[i]);
            ret.pb(v.size());
        }
        else
        {
            int pos=lower_bound(all(v), a[i])-v.begin();
            v[pos]=a[i];
            ret.pb(pos+1);
        }
    }
    return ret;
}

void add(int v, int l, int r, int pos, int val)
{
    if(l==r)
    {
        t[v]=val;
        return;
    }
    int mid=(l+r)>>1;
    if(pos<=mid) add(v<<1, l, mid, pos, val);
    else add(v<<1|1, mid+1, r, pos, val);
    t[v]=max(t[v<<1], t[v<<1|1]);
}

int mx(int v, int l, int r, int tl, int tr)
{
    if(tl<=l and r<=tr) return t[v];
    if(r<tl or tr<l) return 0;
    int mid=(l+r)>>1;
    return max(mx(v<<1, l, mid, tl, tr), mx(v<<1|1, mid+1, r, tl, tr));
}

int main()
{
    SPEED;
    cin>>n>>x;
    for(int i=0; i<n; i++)
        cin>>a[i], v.pb({a[i], i});
    vector<int>l = LIS();
    sort(all(v));
    reverse(all(v));
    reverse(a, a+n);
    for(int i=0; i<n; i++)
        a[i]=-a[i];
    vector<int>r = LIS();
    reverse(all(r));
 
    reverse(a, a+n);
    for(int i=0; i<n; i++)
        a[i]=-a[i];
    a[n]=MOD;
    r.pb(0);
    
    int cur=0;
    for(pii u : v)
    {
        //cout<<u.F<<' '<<u.S<<' '<<l[u.S]<< ' '<<cur<<endl;
        while(cur<n and v[cur].F+x>u.F)
            add(1, 0, n-1, v[cur].S, r[v[cur].S]), cur++;
        ans=max(ans, l[u.S]+mx(1, 0, n-1, u.S+1, n-1));
    }
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 7300 KB Output is correct
2 Correct 127 ms 7376 KB Output is correct
3 Correct 106 ms 7840 KB Output is correct
4 Correct 116 ms 7304 KB Output is correct
5 Correct 70 ms 7844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 2088 KB Output is correct
2 Correct 25 ms 2108 KB Output is correct
3 Correct 25 ms 2036 KB Output is correct
4 Correct 17 ms 2100 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 17 ms 2188 KB Output is correct
7 Correct 21 ms 2092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 4104 KB Output is correct
2 Correct 52 ms 3848 KB Output is correct
3 Correct 108 ms 9180 KB Output is correct
4 Correct 76 ms 8832 KB Output is correct
5 Correct 32 ms 4676 KB Output is correct
6 Correct 55 ms 8600 KB Output is correct
7 Correct 58 ms 9268 KB Output is correct
8 Correct 44 ms 5080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 128 ms 7300 KB Output is correct
28 Correct 127 ms 7376 KB Output is correct
29 Correct 106 ms 7840 KB Output is correct
30 Correct 116 ms 7304 KB Output is correct
31 Correct 70 ms 7844 KB Output is correct
32 Correct 27 ms 2088 KB Output is correct
33 Correct 25 ms 2108 KB Output is correct
34 Correct 25 ms 2036 KB Output is correct
35 Correct 17 ms 2100 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 17 ms 2188 KB Output is correct
38 Correct 21 ms 2092 KB Output is correct
39 Correct 52 ms 4104 KB Output is correct
40 Correct 52 ms 3848 KB Output is correct
41 Correct 108 ms 9180 KB Output is correct
42 Correct 76 ms 8832 KB Output is correct
43 Correct 32 ms 4676 KB Output is correct
44 Correct 55 ms 8600 KB Output is correct
45 Correct 58 ms 9268 KB Output is correct
46 Correct 44 ms 5080 KB Output is correct
47 Correct 53 ms 4684 KB Output is correct
48 Correct 52 ms 5028 KB Output is correct
49 Correct 114 ms 9248 KB Output is correct
50 Correct 74 ms 9024 KB Output is correct
51 Correct 63 ms 7868 KB Output is correct
52 Correct 87 ms 8916 KB Output is correct
53 Correct 58 ms 8852 KB Output is correct
54 Correct 78 ms 9776 KB Output is correct
55 Correct 96 ms 9268 KB Output is correct