Submission #786942

# Submission time Handle Problem Language Result Execution time Memory
786942 2023-07-18T15:18:27 Z gun_gan Global Warming (CEOI18_glo) C++17
100 / 100
254 ms 11164 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MX = 2e5 + 5, inf = 1e9;

int N, X;
int a[MX], dp[MX], id[MX], rdp[MX];

struct segtree {
      int t[4 * MX];
 
      void update(int v, int l, int r, int pos, int val) {
            if(l > pos || r < pos) return;
            if(l == r) {
                  t[v] = val;
                  return;
            }
            int mid = (l + r) >> 1;
            update(v * 2 + 0, l, mid + 0, pos, val);
            update(v * 2 + 1, mid + 1, r, pos, val);
            t[v] = max(t[v * 2 + 0], t[v * 2 + 1]);
      }
 
      int query(int v, int l, int r, int ql, int qr) {
            if(ql > r || qr < l) return 0;
            if(ql <= l && qr >= r) return t[v];
            int mid = (l + r) >> 1;
            return max(query(v * 2 + 0, l, mid + 0, ql, qr), query(v * 2 + 1, mid + 1, r, ql, qr));
      }
} st, tt;

vector<pair<int, int>> v;

int getLow(int x) {
      auto it = lower_bound(v.begin(), v.end(), make_pair(x, -inf));
      return it - v.begin() + 1;
}

int main() {
      cin.tie(0); ios_base::sync_with_stdio(0);

      cin >> N >> X;
      
      for(int i = 1; i <= N; i++) {
            cin >> a[i];
            v.push_back({a[i], i});
      }
      sort(v.begin(), v.end());

      int cnt = 1;
      for(auto [x, p] : v) id[p] = cnt++;

      for(int i = 1; i <= N; i++) {
            dp[i] = st.query(1, 1, N, 1, getLow(a[i]) - 1) + 1;
            st.update(1, 1, N, id[i], dp[i]);
      }

      for(int i = N; i >= 1; i--) {
            rdp[i] = tt.query(1, 1, N, getLow(a[i] + 1), N) + 1;
            tt.update(1, 1, N, id[i], rdp[i]);
      }

      int ans = 0;
      for(int i = 1; i <= N; i++) {
            tt.update(1, 1, N, id[i], 0);

            ans = max(ans, dp[i] + tt.query(1, 1, N, getLow(a[i] - X + 1), N));
      }

      cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 336 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 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 253 ms 9220 KB Output is correct
2 Correct 252 ms 9152 KB Output is correct
3 Correct 248 ms 9220 KB Output is correct
4 Correct 246 ms 9248 KB Output is correct
5 Correct 148 ms 9232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 2688 KB Output is correct
2 Correct 53 ms 2596 KB Output is correct
3 Correct 55 ms 2568 KB Output is correct
4 Correct 30 ms 2636 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 31 ms 2900 KB Output is correct
7 Correct 52 ms 3180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 4812 KB Output is correct
2 Correct 105 ms 4784 KB Output is correct
3 Correct 212 ms 9196 KB Output is correct
4 Correct 113 ms 9256 KB Output is correct
5 Correct 65 ms 5644 KB Output is correct
6 Correct 110 ms 10220 KB Output is correct
7 Correct 113 ms 10800 KB Output is correct
8 Correct 84 ms 5832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 336 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 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 253 ms 9220 KB Output is correct
28 Correct 252 ms 9152 KB Output is correct
29 Correct 248 ms 9220 KB Output is correct
30 Correct 246 ms 9248 KB Output is correct
31 Correct 148 ms 9232 KB Output is correct
32 Correct 54 ms 2688 KB Output is correct
33 Correct 53 ms 2596 KB Output is correct
34 Correct 55 ms 2568 KB Output is correct
35 Correct 30 ms 2636 KB Output is correct
36 Correct 1 ms 328 KB Output is correct
37 Correct 31 ms 2900 KB Output is correct
38 Correct 52 ms 3180 KB Output is correct
39 Correct 98 ms 4812 KB Output is correct
40 Correct 105 ms 4784 KB Output is correct
41 Correct 212 ms 9196 KB Output is correct
42 Correct 113 ms 9256 KB Output is correct
43 Correct 65 ms 5644 KB Output is correct
44 Correct 110 ms 10220 KB Output is correct
45 Correct 113 ms 10800 KB Output is correct
46 Correct 84 ms 5832 KB Output is correct
47 Correct 119 ms 5776 KB Output is correct
48 Correct 124 ms 5872 KB Output is correct
49 Correct 254 ms 11088 KB Output is correct
50 Correct 119 ms 10420 KB Output is correct
51 Correct 100 ms 8940 KB Output is correct
52 Correct 160 ms 10404 KB Output is correct
53 Correct 116 ms 10412 KB Output is correct
54 Correct 118 ms 11164 KB Output is correct
55 Correct 209 ms 11092 KB Output is correct