Submission #1008386

# Submission time Handle Problem Language Result Execution time Memory
1008386 2024-06-26T10:32:50 Z pudelos Global Warming (CEOI18_glo) C++17
100 / 100
353 ms 29968 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=a; i<=b; ++i)
#define ll long long
#define eb emplace_back
#define V vector
const int base=(1<<19);
int n, X;
V<int> A;
map<int, int> ch;

struct SegTree {
  int T[2*base];
  void update(int v, int x) {
    v+=base;
    T[v]=max(T[v], x);
    v/=2;
    while(v>0) {
      T[v]=max(T[2*v], T[2*v+1]);
      v/=2;
    }
  }
  int query(int a, int b) {
    int res=0;
    a+=base-1;
    b+=base+1;
    while(a/2!=b/2) {
      if(a%2==0) res=max(res, T[a+1]);
      if(b%2==1) res=max(res, T[b-1]);
      a/=2; b/=2;
    }
    return res;
  }
} AT, BT;

signed main() {
  cin.tie(0) -> ios_base::sync_with_stdio(0);
  cin >> n >> X;
  A.resize(n+1);
  V<int> all;
  FOR(i, 1, n) {
    cin >> A[i];
    all.eb(A[i]);
    all.eb(A[i]+X);
  }
  sort(all.begin(), all.end());
  int t=0;
  for(int u : all) {
    if(ch[u]==0) ch[u]=++t;
  }
  
  FOR(i, 1, n) {
    int x = A[i];
    int sc = ch[x];
    BT.update(sc, max(BT.query(0, sc-1)+1, AT.query(0, ch[x+X]-1)+1));
    AT.update(sc, AT.query(0, sc-1)+1);
  }
  cout << max(AT.T[1], BT.T[1]) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 259 ms 17084 KB Output is correct
2 Correct 239 ms 17236 KB Output is correct
3 Correct 233 ms 17096 KB Output is correct
4 Correct 249 ms 17356 KB Output is correct
5 Correct 110 ms 11980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 7632 KB Output is correct
2 Correct 58 ms 7632 KB Output is correct
3 Correct 61 ms 7644 KB Output is correct
4 Correct 30 ms 6356 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 32 ms 6472 KB Output is correct
7 Correct 52 ms 6580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 152 ms 13520 KB Output is correct
2 Correct 151 ms 13516 KB Output is correct
3 Correct 353 ms 27668 KB Output is correct
4 Correct 159 ms 14856 KB Output is correct
5 Correct 107 ms 13068 KB Output is correct
6 Correct 186 ms 24772 KB Output is correct
7 Correct 190 ms 25292 KB Output is correct
8 Correct 131 ms 13632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 259 ms 17084 KB Output is correct
28 Correct 239 ms 17236 KB Output is correct
29 Correct 233 ms 17096 KB Output is correct
30 Correct 249 ms 17356 KB Output is correct
31 Correct 110 ms 11980 KB Output is correct
32 Correct 59 ms 7632 KB Output is correct
33 Correct 58 ms 7632 KB Output is correct
34 Correct 61 ms 7644 KB Output is correct
35 Correct 30 ms 6356 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 32 ms 6472 KB Output is correct
38 Correct 52 ms 6580 KB Output is correct
39 Correct 152 ms 13520 KB Output is correct
40 Correct 151 ms 13516 KB Output is correct
41 Correct 353 ms 27668 KB Output is correct
42 Correct 159 ms 14856 KB Output is correct
43 Correct 107 ms 13068 KB Output is correct
44 Correct 186 ms 24772 KB Output is correct
45 Correct 190 ms 25292 KB Output is correct
46 Correct 131 ms 13632 KB Output is correct
47 Correct 136 ms 15056 KB Output is correct
48 Correct 140 ms 15308 KB Output is correct
49 Correct 317 ms 29968 KB Output is correct
50 Correct 139 ms 17864 KB Output is correct
51 Correct 122 ms 11720 KB Output is correct
52 Correct 173 ms 16708 KB Output is correct
53 Correct 200 ms 28360 KB Output is correct
54 Correct 211 ms 28872 KB Output is correct
55 Correct 256 ms 25648 KB Output is correct