Submission #1032455

# Submission time Handle Problem Language Result Execution time Memory
1032455 2024-07-23T19:32:08 Z Mr_Husanboy Radio Towers (IOI22_towers) C++17
23 / 100
4000 ms 9296 KB
#include "towers.h"
#include <bits/stdc++.h>

using namespace std;


#define ff first
#define ss second
#define all(a) (a).begin(), (a).end()
#define ll long long

template<typename T>
int len(T &a){
    return a.size();
}

int n;
vector<int> h;

int mx = 0;

struct SegTree{
  int n;
  vector<int> t;
  SegTree(int n) : n(n), t(2 * n){}
  SegTree(){}

  int merge(int a, int b){
    return max(a, b);
  }

  void upd(int i, int x){
    i += n;
    t[i] = max(t[i], x);
    for(i /= 2; i > 0; i /= 2){
      t[i] = merge(t[i * 2], t[i * 2 + 1]);
    }
  }

  int get(int l, int r){
    l += n; r += n;
    int res = 0;
    while(l <= r){
      if(l & 1){
        res = merge(res, t[l ++]);
      }
      if(!(r & 1)) res = merge(res, t[r --]); 
      l /= 2;
      r /= 2;
    }
    return res;
  }
};

void init(int N, std::vector<int> H) {
  n = N;
  h = H;
  for(int i = 0; i < n; i ++){
    if(h[mx] < h[i]){
      mx = i;
    }
  }
}

int max_towers(int l, int r, int d) {
  vector<int> hh;
  for(int i = l; i <= r; i ++) hh.push_back(h[i]), hh.push_back(h[i] - d),hh.push_back(h[i] + d);
  sort(all(hh));
  hh.erase(unique(all(hh)), hh.end());
  auto getid = [&](int x)->int{
    return lower_bound(all(hh), x) - hh.begin();
  };
  SegTree st1(len(hh) + 1), st2(len(hh) + 1);

  for(int i = l; i <= r; i ++){
    int j = getid(h[i]);
    st1.upd(j, st2.get(getid(h[i] + d), len(hh)) + 1);
    st2.upd(j, st1.get(0, getid(h[i] - d)));
    //cout << st2.get(j, j) << ' ';
  }
  return st1.get(0, len(hh));
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4033 ms 5448 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 500 KB Output is correct
17 Correct 1 ms 592 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 2 ms 576 KB Output is correct
21 Correct 2 ms 576 KB Output is correct
22 Correct 2 ms 600 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 576 KB Output is correct
27 Correct 2 ms 576 KB Output is correct
28 Correct 2 ms 576 KB Output is correct
29 Correct 1 ms 424 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 1 ms 576 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 2 ms 576 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 500 KB Output is correct
17 Correct 1 ms 592 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 2 ms 576 KB Output is correct
21 Correct 2 ms 576 KB Output is correct
22 Correct 2 ms 600 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 576 KB Output is correct
27 Correct 2 ms 576 KB Output is correct
28 Correct 2 ms 576 KB Output is correct
29 Correct 1 ms 424 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 1 ms 576 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 2 ms 576 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 19 ms 2136 KB Output is correct
37 Correct 34 ms 3792 KB Output is correct
38 Correct 26 ms 2228 KB Output is correct
39 Correct 32 ms 3536 KB Output is correct
40 Correct 18 ms 1976 KB Output is correct
41 Correct 76 ms 6604 KB Output is correct
42 Correct 10 ms 1368 KB Output is correct
43 Correct 39 ms 4716 KB Output is correct
44 Correct 14 ms 2156 KB Output is correct
45 Correct 9 ms 1416 KB Output is correct
46 Correct 9 ms 1452 KB Output is correct
47 Correct 37 ms 3788 KB Output is correct
48 Correct 24 ms 2512 KB Output is correct
49 Correct 13 ms 1744 KB Output is correct
50 Correct 17 ms 2768 KB Output is correct
51 Correct 23 ms 4032 KB Output is correct
52 Correct 93 ms 7360 KB Output is correct
53 Correct 90 ms 7360 KB Output is correct
54 Correct 85 ms 7368 KB Output is correct
55 Correct 52 ms 7400 KB Output is correct
56 Correct 51 ms 7368 KB Output is correct
57 Correct 90 ms 7204 KB Output is correct
58 Correct 94 ms 7368 KB Output is correct
59 Correct 99 ms 7368 KB Output is correct
60 Correct 111 ms 7368 KB Output is correct
61 Correct 97 ms 7360 KB Output is correct
62 Correct 79 ms 7612 KB Output is correct
63 Correct 89 ms 7368 KB Output is correct
64 Correct 47 ms 7368 KB Output is correct
65 Correct 55 ms 7364 KB Output is correct
66 Correct 55 ms 7368 KB Output is correct
67 Correct 67 ms 7596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4050 ms 9296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4009 ms 2804 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 500 KB Output is correct
17 Correct 1 ms 592 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 2 ms 576 KB Output is correct
21 Correct 2 ms 576 KB Output is correct
22 Correct 2 ms 600 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 576 KB Output is correct
27 Correct 2 ms 576 KB Output is correct
28 Correct 2 ms 576 KB Output is correct
29 Correct 1 ms 424 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 1 ms 576 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 2 ms 576 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 19 ms 2136 KB Output is correct
37 Correct 34 ms 3792 KB Output is correct
38 Correct 26 ms 2228 KB Output is correct
39 Correct 32 ms 3536 KB Output is correct
40 Correct 18 ms 1976 KB Output is correct
41 Correct 76 ms 6604 KB Output is correct
42 Correct 10 ms 1368 KB Output is correct
43 Correct 39 ms 4716 KB Output is correct
44 Correct 14 ms 2156 KB Output is correct
45 Correct 9 ms 1416 KB Output is correct
46 Correct 9 ms 1452 KB Output is correct
47 Correct 37 ms 3788 KB Output is correct
48 Correct 24 ms 2512 KB Output is correct
49 Correct 13 ms 1744 KB Output is correct
50 Correct 17 ms 2768 KB Output is correct
51 Correct 23 ms 4032 KB Output is correct
52 Correct 93 ms 7360 KB Output is correct
53 Correct 90 ms 7360 KB Output is correct
54 Correct 85 ms 7368 KB Output is correct
55 Correct 52 ms 7400 KB Output is correct
56 Correct 51 ms 7368 KB Output is correct
57 Correct 90 ms 7204 KB Output is correct
58 Correct 94 ms 7368 KB Output is correct
59 Correct 99 ms 7368 KB Output is correct
60 Correct 111 ms 7368 KB Output is correct
61 Correct 97 ms 7360 KB Output is correct
62 Correct 79 ms 7612 KB Output is correct
63 Correct 89 ms 7368 KB Output is correct
64 Correct 47 ms 7368 KB Output is correct
65 Correct 55 ms 7364 KB Output is correct
66 Correct 55 ms 7368 KB Output is correct
67 Correct 67 ms 7596 KB Output is correct
68 Execution timed out 4050 ms 9296 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4033 ms 5448 KB Time limit exceeded
2 Halted 0 ms 0 KB -