Submission #881256

# Submission time Handle Problem Language Result Execution time Memory
881256 2023-12-01T01:50:35 Z votranngocvy Global Warming (CEOI18_glo) C++14
100 / 100
73 ms 18120 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define piii pair<ll,pair<int,int>>
#define fi first
#define se second
#define mp make_pair
const int N = 4e5 + 5;
int n,f[N],g[N],bit[N],val[N];
ll a[N],b[N],x;

void compress() {
    vector<piii>vec;
    for (int i = 1; i <= n; i++) {
        vec.push_back(mp(a[i],mp(i,1)));
        vec.push_back(mp(b[i],mp(i,2)));
    }
    sort(vec.begin(),vec.end());
    val[0] = 1;
    if (vec[0].se.se == 1) a[vec[0].se.fi] = val[0];
    else b[vec[0].se.fi] = val[0];
    for (int i = 1; i < vec.size(); i++) {
        if (vec[i].fi == vec[i - 1].fi) val[i] = val[i - 1];
        else val[i] = i + 1;
        if (vec[i].se.se == 1) a[vec[i].se.fi] = val[i];
        else b[vec[i].se.fi] = val[i];
    }
}

void update(int i,int x) {
    for (; i < N; i += i & (-i)) bit[i] = max(bit[i],x);
}

void update2(int i,int x) {
    for (; i > 0; i -= i & (-i)) bit[i] = max(bit[i],x);
}

int get(int i) {
    int ans = 0;
    for (; i > 0; i -= i & (-i)) ans = max(ans,bit[i]);
    return ans;
}

int get2(int i) {
    int ans = 0;
    for (; i < N; i += i & (-i)) ans = max(ans,bit[i]);
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> x;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = a[i] - x;
    }
    compress();
    for (int i = 1; i <= n; i++) {
        f[i] = get(a[i] - 1) + 1;
        update(a[i],f[i]);
    }
    memset(bit,0,sizeof(bit));
    for (int i = n; i > 0; i--) {
        g[i] = get2(b[i] + 1) + 1;
        update2(a[i],get2(a[i] + 1) + 1);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) ans = max(ans,f[i] + g[i] - 1);
    cout << ans << "\n";
}

Compilation message

glo.cpp: In function 'void compress()':
glo.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (int i = 1; i < vec.size(); i++) {
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 2 ms 8028 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 2 ms 8028 KB Output is correct
5 Correct 2 ms 8028 KB Output is correct
6 Correct 2 ms 8188 KB Output is correct
7 Correct 1 ms 8028 KB Output is correct
8 Correct 2 ms 8028 KB Output is correct
9 Correct 2 ms 8028 KB Output is correct
10 Correct 2 ms 8028 KB Output is correct
11 Correct 2 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 2 ms 8028 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 2 ms 8028 KB Output is correct
5 Correct 2 ms 8028 KB Output is correct
6 Correct 2 ms 8188 KB Output is correct
7 Correct 1 ms 8028 KB Output is correct
8 Correct 2 ms 8028 KB Output is correct
9 Correct 2 ms 8028 KB Output is correct
10 Correct 2 ms 8028 KB Output is correct
11 Correct 2 ms 8028 KB Output is correct
12 Correct 2 ms 8028 KB Output is correct
13 Correct 2 ms 8028 KB Output is correct
14 Correct 2 ms 8028 KB Output is correct
15 Correct 2 ms 8028 KB Output is correct
16 Correct 2 ms 8028 KB Output is correct
17 Correct 2 ms 8028 KB Output is correct
18 Correct 2 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 2 ms 8028 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 2 ms 8028 KB Output is correct
5 Correct 2 ms 8028 KB Output is correct
6 Correct 2 ms 8188 KB Output is correct
7 Correct 1 ms 8028 KB Output is correct
8 Correct 2 ms 8028 KB Output is correct
9 Correct 2 ms 8028 KB Output is correct
10 Correct 2 ms 8028 KB Output is correct
11 Correct 2 ms 8028 KB Output is correct
12 Correct 2 ms 8028 KB Output is correct
13 Correct 2 ms 8028 KB Output is correct
14 Correct 2 ms 8028 KB Output is correct
15 Correct 2 ms 8028 KB Output is correct
16 Correct 2 ms 8028 KB Output is correct
17 Correct 2 ms 8028 KB Output is correct
18 Correct 2 ms 8028 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 2 ms 8284 KB Output is correct
22 Correct 2 ms 8284 KB Output is correct
23 Correct 2 ms 8028 KB Output is correct
24 Correct 2 ms 8024 KB Output is correct
25 Correct 2 ms 8028 KB Output is correct
26 Correct 2 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 16888 KB Output is correct
2 Correct 72 ms 16932 KB Output is correct
3 Correct 69 ms 16836 KB Output is correct
4 Correct 73 ms 18116 KB Output is correct
5 Correct 57 ms 16068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 12604 KB Output is correct
2 Correct 18 ms 12720 KB Output is correct
3 Correct 18 ms 12540 KB Output is correct
4 Correct 16 ms 12468 KB Output is correct
5 Correct 2 ms 8024 KB Output is correct
6 Correct 12 ms 12524 KB Output is correct
7 Correct 17 ms 12732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 13088 KB Output is correct
2 Correct 38 ms 13276 KB Output is correct
3 Correct 72 ms 17088 KB Output is correct
4 Correct 61 ms 16332 KB Output is correct
5 Correct 27 ms 12936 KB Output is correct
6 Correct 47 ms 17360 KB Output is correct
7 Correct 48 ms 16336 KB Output is correct
8 Correct 32 ms 13196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 2 ms 8028 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 2 ms 8028 KB Output is correct
5 Correct 2 ms 8028 KB Output is correct
6 Correct 2 ms 8188 KB Output is correct
7 Correct 1 ms 8028 KB Output is correct
8 Correct 2 ms 8028 KB Output is correct
9 Correct 2 ms 8028 KB Output is correct
10 Correct 2 ms 8028 KB Output is correct
11 Correct 2 ms 8028 KB Output is correct
12 Correct 2 ms 8028 KB Output is correct
13 Correct 2 ms 8028 KB Output is correct
14 Correct 2 ms 8028 KB Output is correct
15 Correct 2 ms 8028 KB Output is correct
16 Correct 2 ms 8028 KB Output is correct
17 Correct 2 ms 8028 KB Output is correct
18 Correct 2 ms 8028 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 2 ms 8284 KB Output is correct
21 Correct 2 ms 8284 KB Output is correct
22 Correct 2 ms 8284 KB Output is correct
23 Correct 2 ms 8028 KB Output is correct
24 Correct 2 ms 8024 KB Output is correct
25 Correct 2 ms 8028 KB Output is correct
26 Correct 2 ms 8028 KB Output is correct
27 Correct 73 ms 16888 KB Output is correct
28 Correct 72 ms 16932 KB Output is correct
29 Correct 69 ms 16836 KB Output is correct
30 Correct 73 ms 18116 KB Output is correct
31 Correct 57 ms 16068 KB Output is correct
32 Correct 18 ms 12604 KB Output is correct
33 Correct 18 ms 12720 KB Output is correct
34 Correct 18 ms 12540 KB Output is correct
35 Correct 16 ms 12468 KB Output is correct
36 Correct 2 ms 8024 KB Output is correct
37 Correct 12 ms 12524 KB Output is correct
38 Correct 17 ms 12732 KB Output is correct
39 Correct 36 ms 13088 KB Output is correct
40 Correct 38 ms 13276 KB Output is correct
41 Correct 72 ms 17088 KB Output is correct
42 Correct 61 ms 16332 KB Output is correct
43 Correct 27 ms 12936 KB Output is correct
44 Correct 47 ms 17360 KB Output is correct
45 Correct 48 ms 16336 KB Output is correct
46 Correct 32 ms 13196 KB Output is correct
47 Correct 35 ms 13052 KB Output is correct
48 Correct 35 ms 13188 KB Output is correct
49 Correct 70 ms 16580 KB Output is correct
50 Correct 58 ms 16220 KB Output is correct
51 Correct 36 ms 16080 KB Output is correct
52 Correct 44 ms 17360 KB Output is correct
53 Correct 48 ms 15968 KB Output is correct
54 Correct 50 ms 18120 KB Output is correct
55 Correct 64 ms 16336 KB Output is correct