Submission #199663

# Submission time Handle Problem Language Result Execution time Memory
199663 2020-02-02T13:32:07 Z gratus907 Global Warming (CEOI18_glo) C++17
100 / 100
177 ms 8616 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ll long long
#define eps 1e-7
#define sz(v) ((int)(v).size())
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using pii = pair<int, int>;
#define int ll

inline int count_element(vector <int> & v, int x, bool incl)
{
    auto ed = v.end();
    auto st = v.begin();
    if (incl)
        ed = upper_bound(all(v),x);
    else
        ed = lower_bound(all(v),x);
    return (ed - st);
}

int seq[202020];
int indlist[202020];
int n, x, ans;
int32_t main()
{
    cin >> n >> x;
    for (int i = 0; i<n; i++) indlist[i] = n;
    vector<int> lis_front(n+1, INT_MAX);
    vector<int> lds_back(n+1, -INT_MAX);
    for (int i = 0; i<n; i++)
        cin >> seq[i];
    lis_front[0] = -1;
    lds_back[n] = INT_MAX;
    for (int i = 0; i<n; i++)
    {
        int ind = count_element(lis_front, seq[i], false);
        lis_front[ind] = seq[i];
        ans = max(ans, ind);
        indlist[i] += ind;
    }
    for (int i = n-1; i>=0; i--)
    {
        int ind = count_element(lds_back, seq[i]-x+1, false);
        ans = max(ans, indlist[i]-ind);
        int orind = count_element(lds_back, seq[i], true);
        lds_back[orind-1] = seq[i];
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 12 ms 380 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 12 ms 380 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 12 ms 380 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 6 ms 376 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
21 Correct 6 ms 376 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 6 ms 376 KB Output is correct
25 Correct 6 ms 376 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 171 ms 8568 KB Output is correct
2 Correct 177 ms 8568 KB Output is correct
3 Correct 176 ms 8568 KB Output is correct
4 Correct 173 ms 8616 KB Output is correct
5 Correct 124 ms 7800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 2428 KB Output is correct
2 Correct 46 ms 2428 KB Output is correct
3 Correct 46 ms 2428 KB Output is correct
4 Correct 34 ms 2168 KB Output is correct
5 Correct 5 ms 248 KB Output is correct
6 Correct 33 ms 2168 KB Output is correct
7 Correct 44 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 4472 KB Output is correct
2 Correct 86 ms 4472 KB Output is correct
3 Correct 164 ms 8568 KB Output is correct
4 Correct 126 ms 7800 KB Output is correct
5 Correct 64 ms 4088 KB Output is correct
6 Correct 114 ms 7416 KB Output is correct
7 Correct 151 ms 8184 KB Output is correct
8 Correct 83 ms 4472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 12 ms 380 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 6 ms 376 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
21 Correct 6 ms 376 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 6 ms 376 KB Output is correct
25 Correct 6 ms 376 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 171 ms 8568 KB Output is correct
28 Correct 177 ms 8568 KB Output is correct
29 Correct 176 ms 8568 KB Output is correct
30 Correct 173 ms 8616 KB Output is correct
31 Correct 124 ms 7800 KB Output is correct
32 Correct 45 ms 2428 KB Output is correct
33 Correct 46 ms 2428 KB Output is correct
34 Correct 46 ms 2428 KB Output is correct
35 Correct 34 ms 2168 KB Output is correct
36 Correct 5 ms 248 KB Output is correct
37 Correct 33 ms 2168 KB Output is correct
38 Correct 44 ms 2424 KB Output is correct
39 Correct 85 ms 4472 KB Output is correct
40 Correct 86 ms 4472 KB Output is correct
41 Correct 164 ms 8568 KB Output is correct
42 Correct 126 ms 7800 KB Output is correct
43 Correct 64 ms 4088 KB Output is correct
44 Correct 114 ms 7416 KB Output is correct
45 Correct 151 ms 8184 KB Output is correct
46 Correct 83 ms 4472 KB Output is correct
47 Correct 87 ms 4600 KB Output is correct
48 Correct 86 ms 4472 KB Output is correct
49 Correct 175 ms 8544 KB Output is correct
50 Correct 121 ms 7928 KB Output is correct
51 Correct 92 ms 5880 KB Output is correct
52 Correct 129 ms 7928 KB Output is correct
53 Correct 125 ms 7928 KB Output is correct
54 Correct 155 ms 8568 KB Output is correct
55 Correct 161 ms 8568 KB Output is correct