Submission #467951

# Submission time Handle Problem Language Result Execution time Memory
467951 2021-08-25T17:41:55 Z ivan_tudor Global Warming (CEOI18_glo) C++14
100 / 100
1041 ms 129848 KB
#include<bits/stdc++.h>
using namespace std;
const int VMAX = 1e9;
struct aintnode{
  int l, r;
  int mval;
  aintnode *ls, *rs;
  aintnode(int _l, int _r){
    l = _l;
    r = _r;
    mval = 0;
    ls = rs  = NULL;
  }
};
void update(aintnode *node, int poz, int val){
  int l = node->l, r = node->r;
  if(poz < l || poz > r)
    return;
  if(l == r){
    node->mval = val;
    return;
  }
  int mid = (l + r)/2;
  if(poz <= mid){
    if(node->ls == NULL)
      node->ls = new aintnode(l, mid);
    update(node->ls, poz, val);
  }
  else{
    if(node->rs == NULL)
      node->rs = new aintnode(mid +1, r);
    update(node->rs, poz, val);
  }
  node->mval = 0;
  if(node->ls != NULL)
    node->mval = max(node->mval, node->ls->mval);
  if(node->rs != NULL)
    node->mval = max(node->mval, node->rs->mval);
}
int query(aintnode *node, int ql, int qr){
  if(node == NULL)
    return 0;
  if(qr < node->l || ql > node->r)
    return 0;
  if(ql <= node->l && node->r <= qr)
    return node->mval;
  return max(query(node->ls, ql, qr), query(node->rs, ql, qr));
}
void clr(aintnode *node){
  if(node->ls != NULL)
    clr(node->ls);
  if(node->rs != NULL)
    clr(node->rs);
  delete node;
}
const int N = 200005;
int v[N];
int r[N];
int main()
{
  //freopen(".in","r",stdin);
  ios::sync_with_stdio(false);
  cin.tie(0),cout.tie(0);
  int n, d;
  cin>>n>>d;
  for(int i = 1; i<=n; i++){
    cin>>v[i];
  }
  aintnode *root = new aintnode(1, VMAX);
  for(int i = n; i>=1; i--){
    int lenmax = query(root, v[i] + 1, VMAX);
    r[i] = lenmax + 1;
    update(root, v[i], r[i]);
  }
  clr(root);
  root = new aintnode(1, VMAX);
  int ans = 0;
  for(int i = 1; i<=n; i++){
    int lmaxd = query(root, 1, v[i] + d - 1);
    ans = max(ans, lmaxd + r[i]);
    int lenm = query(root, 1, v[i] - 1);
    update(root, v[i], lenm + 1);
  }
  cout<<ans;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 4 ms 1308 KB Output is correct
20 Correct 4 ms 1228 KB Output is correct
21 Correct 6 ms 1228 KB Output is correct
22 Correct 4 ms 1228 KB Output is correct
23 Correct 3 ms 836 KB Output is correct
24 Correct 3 ms 844 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1027 ms 129708 KB Output is correct
2 Correct 1020 ms 129708 KB Output is correct
3 Correct 991 ms 129848 KB Output is correct
4 Correct 961 ms 129724 KB Output is correct
5 Correct 443 ms 70596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 214 ms 37380 KB Output is correct
2 Correct 267 ms 37348 KB Output is correct
3 Correct 219 ms 37316 KB Output is correct
4 Correct 105 ms 20152 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 80 ms 4500 KB Output is correct
7 Correct 158 ms 26896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 425 ms 69752 KB Output is correct
2 Correct 451 ms 69612 KB Output is correct
3 Correct 981 ms 129664 KB Output is correct
4 Correct 361 ms 70700 KB Output is correct
5 Correct 153 ms 10996 KB Output is correct
6 Correct 276 ms 20828 KB Output is correct
7 Correct 273 ms 21484 KB Output is correct
8 Correct 303 ms 50372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 4 ms 1308 KB Output is correct
20 Correct 4 ms 1228 KB Output is correct
21 Correct 6 ms 1228 KB Output is correct
22 Correct 4 ms 1228 KB Output is correct
23 Correct 3 ms 836 KB Output is correct
24 Correct 3 ms 844 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 316 KB Output is correct
27 Correct 1027 ms 129708 KB Output is correct
28 Correct 1020 ms 129708 KB Output is correct
29 Correct 991 ms 129848 KB Output is correct
30 Correct 961 ms 129724 KB Output is correct
31 Correct 443 ms 70596 KB Output is correct
32 Correct 214 ms 37380 KB Output is correct
33 Correct 267 ms 37348 KB Output is correct
34 Correct 219 ms 37316 KB Output is correct
35 Correct 105 ms 20152 KB Output is correct
36 Correct 0 ms 332 KB Output is correct
37 Correct 80 ms 4500 KB Output is correct
38 Correct 158 ms 26896 KB Output is correct
39 Correct 425 ms 69752 KB Output is correct
40 Correct 451 ms 69612 KB Output is correct
41 Correct 981 ms 129664 KB Output is correct
42 Correct 361 ms 70700 KB Output is correct
43 Correct 153 ms 10996 KB Output is correct
44 Correct 276 ms 20828 KB Output is correct
45 Correct 273 ms 21484 KB Output is correct
46 Correct 303 ms 50372 KB Output is correct
47 Correct 471 ms 69684 KB Output is correct
48 Correct 461 ms 69760 KB Output is correct
49 Correct 1041 ms 129732 KB Output is correct
50 Correct 459 ms 70596 KB Output is correct
51 Correct 230 ms 11732 KB Output is correct
52 Correct 349 ms 21924 KB Output is correct
53 Correct 287 ms 22008 KB Output is correct
54 Correct 321 ms 22640 KB Output is correct
55 Correct 715 ms 94132 KB Output is correct