Submission #397804

# Submission time Handle Problem Language Result Execution time Memory
397804 2021-05-03T06:47:50 Z iANikzad Global Warming (CEOI18_glo) C++17
100 / 100
78 ms 10052 KB
#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define F first
#define S second
#define debug(x) cerr<<#x<<" :"<<x<<"\n"
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define FAST ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
#define int long long

typedef long long ll;
typedef long double ld;

const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const int mlog = 20;
const int SQ = 400;

int a[maxn];

int L[maxn], R[maxn];
int dp[maxn], pd[maxn];

int32_t main()
{
    FAST;

    int n, x;
    cin >> n >> x;

    for(int i = 0; i < n; i++)
        cin >> a[i], dp[i] = pd[i] = +INF;

    for(int i = 0; i < n; i++)
    {
        int pos = lower_bound(dp, dp + n, a[i]) - dp;
        L[i] = pos + 1;

        dp[pos] = a[i];
    }

    for(int i = n - 1; i >= 0; i--)
    {
        int pos = lower_bound(pd, pd + n, -a[i] + x) - pd;
        R[i] = pos + 1;

        int npos = lower_bound(pd ,pd + n, -a[i]) - pd;
        pd[npos] = -a[i];
    }

    int ans = 0;
    for(int i = 0; i < n; i++) ans = max(ans, R[i] + L[i] - 1);

    cout << ans << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 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 68 ms 8024 KB Output is correct
2 Correct 68 ms 8712 KB Output is correct
3 Correct 70 ms 8676 KB Output is correct
4 Correct 78 ms 8684 KB Output is correct
5 Correct 53 ms 8748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 2232 KB Output is correct
2 Correct 18 ms 2712 KB Output is correct
3 Correct 17 ms 2756 KB Output is correct
4 Correct 14 ms 2508 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 14 ms 2508 KB Output is correct
7 Correct 14 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 4164 KB Output is correct
2 Correct 31 ms 5268 KB Output is correct
3 Correct 64 ms 10024 KB Output is correct
4 Correct 57 ms 9284 KB Output is correct
5 Correct 27 ms 4804 KB Output is correct
6 Correct 48 ms 8888 KB Output is correct
7 Correct 50 ms 9544 KB Output is correct
8 Correct 27 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 68 ms 8024 KB Output is correct
28 Correct 68 ms 8712 KB Output is correct
29 Correct 70 ms 8676 KB Output is correct
30 Correct 78 ms 8684 KB Output is correct
31 Correct 53 ms 8748 KB Output is correct
32 Correct 16 ms 2232 KB Output is correct
33 Correct 18 ms 2712 KB Output is correct
34 Correct 17 ms 2756 KB Output is correct
35 Correct 14 ms 2508 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 14 ms 2508 KB Output is correct
38 Correct 14 ms 2764 KB Output is correct
39 Correct 31 ms 4164 KB Output is correct
40 Correct 31 ms 5268 KB Output is correct
41 Correct 64 ms 10024 KB Output is correct
42 Correct 57 ms 9284 KB Output is correct
43 Correct 27 ms 4804 KB Output is correct
44 Correct 48 ms 8888 KB Output is correct
45 Correct 50 ms 9544 KB Output is correct
46 Correct 27 ms 5200 KB Output is correct
47 Correct 33 ms 5188 KB Output is correct
48 Correct 33 ms 5184 KB Output is correct
49 Correct 72 ms 10012 KB Output is correct
50 Correct 54 ms 9284 KB Output is correct
51 Correct 42 ms 7012 KB Output is correct
52 Correct 55 ms 9284 KB Output is correct
53 Correct 51 ms 9344 KB Output is correct
54 Correct 52 ms 10004 KB Output is correct
55 Correct 61 ms 10052 KB Output is correct