Submission #1023897

# Submission time Handle Problem Language Result Execution time Memory
1023897 2024-07-15T09:04:00 Z vjudge1 Global Warming (CEOI18_glo) C++14
100 / 100
107 ms 7084 KB
#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int maxn = 4e5 + 7;

int n , x , a[maxn] , b[maxn];

struct Fenwick
{
	int bit[maxn];
	void update(int pos,int val)
	{
		for(;pos < maxn;pos += pos & -pos)bit[pos] = max(bit[pos],val);
	}
	int get(int pos)
	{
		int res = 0;
		for(;pos > 0;pos -= pos & -pos)res = max(res,bit[pos]);
		return res;
	}
};

Fenwick sta , stb;



void compress()
{
    vector <int> order;
    for(int i = 1; i <= n; i++)
    {
        order.push_back(a[i]);
        order.push_back(a[i] - x);
    }
    sort(order.begin() , order.end());
    order.erase(unique(order.begin(),order.end()),order.end());
    for(int i = 1; i <= n; i++)
    {
        b[i] = lower_bound(order.begin() , order.end() , a[i] - x) - order.begin() + 1;
        a[i] = lower_bound(order.begin() , order.end() , a[i]) - order.begin() + 1;
    }
}

void solve()
{
    cin >> n >> x;
    for(int i = 1; i <= n; i++) cin >> a[i];

    compress();

    //for(int i = 1; i <= n; i++) cout << a[i] << ' '; cout << '\n';
    //for(int i = 1; i <= n; i++) cout << b[i] << ' '; cout << '\n';

    int ans = 0;

    for(int i = 1; i <= n; i++)
    {
        // b[i] = a[i] - x
        int geta1 = sta.get(b[i] - 1); // lay nhung thg a[i] - x
        ans = max(ans , geta1 + 1);
        int getb2 = stb.get(a[i] - 1);// lay a[i]
        int geta2 = sta.get(a[i] - 1); // lay nhung thg a[i] - x

        ans = max(ans , max(getb2 , geta2) + 1);

        //cout << geta1 << ' ' << geta2 << ' ' << getb2 << '\n';

        stb.update(a[i] , max(getb2 , geta2) + 1);
        sta.update(b[i] , geta1 + 1);
    }
    cout << ans << '\n';
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 392 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 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 392 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 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 392 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 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 5520 KB Output is correct
2 Correct 89 ms 5576 KB Output is correct
3 Correct 102 ms 5472 KB Output is correct
4 Correct 88 ms 5628 KB Output is correct
5 Correct 41 ms 4820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2136 KB Output is correct
2 Correct 23 ms 2132 KB Output is correct
3 Correct 21 ms 2216 KB Output is correct
4 Correct 11 ms 1616 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 11 ms 1736 KB Output is correct
7 Correct 18 ms 2124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 3032 KB Output is correct
2 Correct 49 ms 3032 KB Output is correct
3 Correct 107 ms 5672 KB Output is correct
4 Correct 48 ms 4804 KB Output is correct
5 Correct 28 ms 2760 KB Output is correct
6 Correct 48 ms 4776 KB Output is correct
7 Correct 50 ms 5292 KB Output is correct
8 Correct 38 ms 3196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 392 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 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 91 ms 5520 KB Output is correct
28 Correct 89 ms 5576 KB Output is correct
29 Correct 102 ms 5472 KB Output is correct
30 Correct 88 ms 5628 KB Output is correct
31 Correct 41 ms 4820 KB Output is correct
32 Correct 22 ms 2136 KB Output is correct
33 Correct 23 ms 2132 KB Output is correct
34 Correct 21 ms 2216 KB Output is correct
35 Correct 11 ms 1616 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 11 ms 1736 KB Output is correct
38 Correct 18 ms 2124 KB Output is correct
39 Correct 49 ms 3032 KB Output is correct
40 Correct 49 ms 3032 KB Output is correct
41 Correct 107 ms 5672 KB Output is correct
42 Correct 48 ms 4804 KB Output is correct
43 Correct 28 ms 2760 KB Output is correct
44 Correct 48 ms 4776 KB Output is correct
45 Correct 50 ms 5292 KB Output is correct
46 Correct 38 ms 3196 KB Output is correct
47 Correct 45 ms 3776 KB Output is correct
48 Correct 45 ms 3760 KB Output is correct
49 Correct 98 ms 7084 KB Output is correct
50 Correct 43 ms 4812 KB Output is correct
51 Correct 37 ms 4056 KB Output is correct
52 Correct 50 ms 5036 KB Output is correct
53 Correct 56 ms 5088 KB Output is correct
54 Correct 52 ms 5576 KB Output is correct
55 Correct 78 ms 6568 KB Output is correct