Submission #625960

# Submission time Handle Problem Language Result Execution time Memory
625960 2022-08-11T04:52:26 Z ITO Radio Towers (IOI22_towers) C++17
27 / 100
4000 ms 13916 KB
#include "towers.h"

#include <bits/stdc++.h>
using namespace std;
int n, h[100000], hi[100000];
vector<pair<int, int>> pv, ppv;

int av[400000];
vector<int> aa[400000];

int build(int id, int ll, int rr) {
  if (ll == rr) {
    av[id] = h[ll];
    //aa[id].push_back(h[ll]);
  } else {
    int m = (ll + rr) / 2, i = 0, j = 0;
    av[id] = max(build(id * 2, ll, m), build(id * 2 + 1, m + 1, rr));
    /*while (i < aa[id * 2].size() && j < aa[id * 2 + 1].size()) {
      if (aa[id * 2][i] <= aa[id * 2 + 1][j]) {
        aa[id].push_back(aa[id * 2][i]);
        i++;
      } else {
        aa[id].push_back(aa[id * 2 + 1][j]);
        j++;
      }
    }
    while (i < aa[id * 2].size()) {
      aa[id].push_back(aa[id * 2][i]);
      i++;
    }
    while (j < aa[id * 2 + 1].size()) {
      aa[id].push_back(aa[id * 2 + 1][j]);
      j++;
    }*/
  }
  return av[id];
}
int ma(int id, int l, int r, int ll, int rr) {
  if (r < ll || l > rr) return 0;
  if (ll >= l && rr <= r) return av[id];
  int m = (l + r) / 2;
  return max(ma(id * 2, l, r, ll, m), ma(id * 2 + 1, l, r, m + 1, rr));
}
int lar(int id, int va, int l, int r, int ll, int rr) {
  if (r < ll || l > rr || av[id] < va) return -1;
  if (ll == rr) return ll;
  int m = (l + r) / 2;
  int te = lar(id * 2 + 1, va, l, r, m + 1, rr);
  if (te >= 0) return te;
  return lar(id * 2, va, l, r, ll, m);
}
int lal(int id, int va, int l, int r, int ll, int rr) {
  if (r < ll || l > rr || av[id] < va) return -1;
  if (ll == rr) return ll;
  int m = (l + r) / 2;
  int te = lar(id * 2, va, l, r, ll, m);
  if (te >= 0) return te;
  return lar(id * 2 + 1, va, l, r, m + 1, rr);
}
int bel(int id, int va, int l, int r, int ll, int rr) {
  if (r < ll || l > rr) return 0;
  if (ll == rr) {
    return upper_bound(aa[id].begin(), aa[id].end(), va) - aa[id].begin();
  }
  int m = (l + r) / 2;
  return bel(id * 2, va, l, r, ll, m) + bel(id * 2 + 1, va, l, r, m + 1, rr);
}
void init(int N, std::vector<int> H) {
  n = N;
  pv.push_back({1000000001, -1});
  for (int i = 0; i < N; i++) {
    h[i] = H[i];
    int te = pv.size();
    if (te >= 2 && ((pv[te - 1].first > pv[te - 2].first && h[i] > pv[te - 1].first) || (pv[te - 1].first < pv[te - 2].first && h[i] < pv[te - 1].first))) {
      pv[te - 1] = make_pair(h[i], i);
    } else {
      pv.push_back({h[i], i});
    }
    hi[i] = (pv.size() - 1);
  }
  for (int i = 1; i < pv.size(); i += 2) {
    if (i == pv.size() - 1) ppv.push_back({pv[i - 1].first - pv[i].first, pv[i].second});
    else ppv.push_back({min(pv[i - 1].first - pv[i].first, pv[i + 1].first - pv[i].first), pv[i].second});
  }
  build(1, 0, N - 1);
}

int max_towers(int L, int R, int D) {
  int c = 1, co = 0, bo = 1, ex = 2000000000;
  for (int i = L; i <= R; i++) {
    if (bo == 1) {
      if (h[i] > ex) ex = h[i];
      else if (h[i] <= ex - D) {
        bo = 0;
        ex = h[i];
        co++;
      }
    } else {
      if (h[i] < ex) ex = h[i];
      else if (h[i] - D >= ex) {
        bo = 1;
        ex = h[i];
      }
    }
  }
  return co;
}

Compilation message

towers.cpp: In function 'int build(int, int, int)':
towers.cpp:16:28: warning: unused variable 'i' [-Wunused-variable]
   16 |     int m = (ll + rr) / 2, i = 0, j = 0;
      |                            ^
towers.cpp:16:35: warning: unused variable 'j' [-Wunused-variable]
   16 |     int m = (ll + rr) / 2, i = 0, j = 0;
      |                                   ^
towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:81:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |   for (int i = 1; i < pv.size(); i += 2) {
      |                   ~~^~~~~~~~~~~
towers.cpp:82:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     if (i == pv.size() - 1) ppv.push_back({pv[i - 1].first - pv[i].first, pv[i].second});
      |         ~~^~~~~~~~~~~~~~~~
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:89:7: warning: unused variable 'c' [-Wunused-variable]
   89 |   int c = 1, co = 0, bo = 1, ex = 2000000000;
      |       ^
# Verdict Execution time Memory Grader output
1 Correct 976 ms 11084 KB Output is correct
2 Correct 3228 ms 12252 KB Output is correct
3 Correct 2982 ms 12276 KB Output is correct
4 Correct 3078 ms 12284 KB Output is correct
5 Correct 3176 ms 12264 KB Output is correct
6 Correct 2319 ms 12256 KB Output is correct
7 Correct 3116 ms 12272 KB Output is correct
8 Correct 5 ms 9680 KB Output is correct
9 Correct 5 ms 9680 KB Output is correct
10 Correct 6 ms 9680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9680 KB Output is correct
2 Correct 6 ms 9680 KB Output is correct
3 Correct 5 ms 9680 KB Output is correct
4 Correct 6 ms 9724 KB Output is correct
5 Correct 7 ms 9680 KB Output is correct
6 Correct 7 ms 9680 KB Output is correct
7 Correct 6 ms 9680 KB Output is correct
8 Correct 6 ms 9680 KB Output is correct
9 Correct 5 ms 9680 KB Output is correct
10 Correct 6 ms 9680 KB Output is correct
11 Correct 5 ms 9680 KB Output is correct
12 Correct 5 ms 9680 KB Output is correct
13 Correct 5 ms 9680 KB Output is correct
14 Correct 5 ms 9680 KB Output is correct
15 Correct 5 ms 9680 KB Output is correct
16 Correct 5 ms 9680 KB Output is correct
17 Correct 5 ms 9720 KB Output is correct
18 Correct 5 ms 9680 KB Output is correct
19 Correct 5 ms 9740 KB Output is correct
20 Correct 7 ms 9680 KB Output is correct
21 Correct 5 ms 9680 KB Output is correct
22 Correct 5 ms 9680 KB Output is correct
23 Correct 5 ms 9648 KB Output is correct
24 Correct 6 ms 9680 KB Output is correct
25 Correct 5 ms 9680 KB Output is correct
26 Correct 5 ms 9680 KB Output is correct
27 Correct 5 ms 9680 KB Output is correct
28 Correct 6 ms 9680 KB Output is correct
29 Correct 5 ms 9680 KB Output is correct
30 Correct 5 ms 9680 KB Output is correct
31 Correct 7 ms 9692 KB Output is correct
32 Correct 6 ms 9680 KB Output is correct
33 Correct 6 ms 9752 KB Output is correct
34 Correct 5 ms 9680 KB Output is correct
35 Correct 5 ms 9680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9680 KB Output is correct
2 Correct 6 ms 9680 KB Output is correct
3 Correct 5 ms 9680 KB Output is correct
4 Correct 6 ms 9724 KB Output is correct
5 Correct 7 ms 9680 KB Output is correct
6 Correct 7 ms 9680 KB Output is correct
7 Correct 6 ms 9680 KB Output is correct
8 Correct 6 ms 9680 KB Output is correct
9 Correct 5 ms 9680 KB Output is correct
10 Correct 6 ms 9680 KB Output is correct
11 Correct 5 ms 9680 KB Output is correct
12 Correct 5 ms 9680 KB Output is correct
13 Correct 5 ms 9680 KB Output is correct
14 Correct 5 ms 9680 KB Output is correct
15 Correct 5 ms 9680 KB Output is correct
16 Correct 5 ms 9680 KB Output is correct
17 Correct 5 ms 9720 KB Output is correct
18 Correct 5 ms 9680 KB Output is correct
19 Correct 5 ms 9740 KB Output is correct
20 Correct 7 ms 9680 KB Output is correct
21 Correct 5 ms 9680 KB Output is correct
22 Correct 5 ms 9680 KB Output is correct
23 Correct 5 ms 9648 KB Output is correct
24 Correct 6 ms 9680 KB Output is correct
25 Correct 5 ms 9680 KB Output is correct
26 Correct 5 ms 9680 KB Output is correct
27 Correct 5 ms 9680 KB Output is correct
28 Correct 6 ms 9680 KB Output is correct
29 Correct 5 ms 9680 KB Output is correct
30 Correct 5 ms 9680 KB Output is correct
31 Correct 7 ms 9692 KB Output is correct
32 Correct 6 ms 9680 KB Output is correct
33 Correct 6 ms 9752 KB Output is correct
34 Correct 5 ms 9680 KB Output is correct
35 Correct 5 ms 9680 KB Output is correct
36 Correct 19 ms 11992 KB Output is correct
37 Correct 19 ms 13516 KB Output is correct
38 Correct 22 ms 13536 KB Output is correct
39 Correct 20 ms 13908 KB Output is correct
40 Correct 20 ms 13888 KB Output is correct
41 Correct 28 ms 13912 KB Output is correct
42 Correct 18 ms 13904 KB Output is correct
43 Correct 17 ms 12252 KB Output is correct
44 Correct 18 ms 12252 KB Output is correct
45 Correct 16 ms 12252 KB Output is correct
46 Correct 17 ms 12248 KB Output is correct
47 Correct 20 ms 13524 KB Output is correct
48 Correct 20 ms 13908 KB Output is correct
49 Correct 19 ms 13908 KB Output is correct
50 Correct 16 ms 12252 KB Output is correct
51 Correct 17 ms 12312 KB Output is correct
52 Correct 19 ms 13520 KB Output is correct
53 Correct 19 ms 13908 KB Output is correct
54 Correct 23 ms 13916 KB Output is correct
55 Correct 19 ms 12260 KB Output is correct
56 Correct 17 ms 12256 KB Output is correct
57 Correct 22 ms 13136 KB Output is correct
58 Correct 19 ms 13540 KB Output is correct
59 Correct 20 ms 13528 KB Output is correct
60 Correct 19 ms 13904 KB Output is correct
61 Correct 21 ms 13908 KB Output is correct
62 Correct 23 ms 13916 KB Output is correct
63 Correct 21 ms 13912 KB Output is correct
64 Correct 17 ms 12240 KB Output is correct
65 Correct 16 ms 12268 KB Output is correct
66 Correct 16 ms 12272 KB Output is correct
67 Correct 25 ms 12256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4037 ms 13520 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3373 ms 10576 KB Output is correct
2 Execution timed out 4053 ms 13520 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9680 KB Output is correct
2 Correct 6 ms 9680 KB Output is correct
3 Correct 5 ms 9680 KB Output is correct
4 Correct 6 ms 9724 KB Output is correct
5 Correct 7 ms 9680 KB Output is correct
6 Correct 7 ms 9680 KB Output is correct
7 Correct 6 ms 9680 KB Output is correct
8 Correct 6 ms 9680 KB Output is correct
9 Correct 5 ms 9680 KB Output is correct
10 Correct 6 ms 9680 KB Output is correct
11 Correct 5 ms 9680 KB Output is correct
12 Correct 5 ms 9680 KB Output is correct
13 Correct 5 ms 9680 KB Output is correct
14 Correct 5 ms 9680 KB Output is correct
15 Correct 5 ms 9680 KB Output is correct
16 Correct 5 ms 9680 KB Output is correct
17 Correct 5 ms 9720 KB Output is correct
18 Correct 5 ms 9680 KB Output is correct
19 Correct 5 ms 9740 KB Output is correct
20 Correct 7 ms 9680 KB Output is correct
21 Correct 5 ms 9680 KB Output is correct
22 Correct 5 ms 9680 KB Output is correct
23 Correct 5 ms 9648 KB Output is correct
24 Correct 6 ms 9680 KB Output is correct
25 Correct 5 ms 9680 KB Output is correct
26 Correct 5 ms 9680 KB Output is correct
27 Correct 5 ms 9680 KB Output is correct
28 Correct 6 ms 9680 KB Output is correct
29 Correct 5 ms 9680 KB Output is correct
30 Correct 5 ms 9680 KB Output is correct
31 Correct 7 ms 9692 KB Output is correct
32 Correct 6 ms 9680 KB Output is correct
33 Correct 6 ms 9752 KB Output is correct
34 Correct 5 ms 9680 KB Output is correct
35 Correct 5 ms 9680 KB Output is correct
36 Correct 19 ms 11992 KB Output is correct
37 Correct 19 ms 13516 KB Output is correct
38 Correct 22 ms 13536 KB Output is correct
39 Correct 20 ms 13908 KB Output is correct
40 Correct 20 ms 13888 KB Output is correct
41 Correct 28 ms 13912 KB Output is correct
42 Correct 18 ms 13904 KB Output is correct
43 Correct 17 ms 12252 KB Output is correct
44 Correct 18 ms 12252 KB Output is correct
45 Correct 16 ms 12252 KB Output is correct
46 Correct 17 ms 12248 KB Output is correct
47 Correct 20 ms 13524 KB Output is correct
48 Correct 20 ms 13908 KB Output is correct
49 Correct 19 ms 13908 KB Output is correct
50 Correct 16 ms 12252 KB Output is correct
51 Correct 17 ms 12312 KB Output is correct
52 Correct 19 ms 13520 KB Output is correct
53 Correct 19 ms 13908 KB Output is correct
54 Correct 23 ms 13916 KB Output is correct
55 Correct 19 ms 12260 KB Output is correct
56 Correct 17 ms 12256 KB Output is correct
57 Correct 22 ms 13136 KB Output is correct
58 Correct 19 ms 13540 KB Output is correct
59 Correct 20 ms 13528 KB Output is correct
60 Correct 19 ms 13904 KB Output is correct
61 Correct 21 ms 13908 KB Output is correct
62 Correct 23 ms 13916 KB Output is correct
63 Correct 21 ms 13912 KB Output is correct
64 Correct 17 ms 12240 KB Output is correct
65 Correct 16 ms 12268 KB Output is correct
66 Correct 16 ms 12272 KB Output is correct
67 Correct 25 ms 12256 KB Output is correct
68 Execution timed out 4037 ms 13520 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 976 ms 11084 KB Output is correct
2 Correct 3228 ms 12252 KB Output is correct
3 Correct 2982 ms 12276 KB Output is correct
4 Correct 3078 ms 12284 KB Output is correct
5 Correct 3176 ms 12264 KB Output is correct
6 Correct 2319 ms 12256 KB Output is correct
7 Correct 3116 ms 12272 KB Output is correct
8 Correct 5 ms 9680 KB Output is correct
9 Correct 5 ms 9680 KB Output is correct
10 Correct 6 ms 9680 KB Output is correct
11 Correct 4 ms 9680 KB Output is correct
12 Correct 6 ms 9680 KB Output is correct
13 Correct 5 ms 9680 KB Output is correct
14 Correct 6 ms 9724 KB Output is correct
15 Correct 7 ms 9680 KB Output is correct
16 Correct 7 ms 9680 KB Output is correct
17 Correct 6 ms 9680 KB Output is correct
18 Correct 6 ms 9680 KB Output is correct
19 Correct 5 ms 9680 KB Output is correct
20 Correct 6 ms 9680 KB Output is correct
21 Correct 5 ms 9680 KB Output is correct
22 Correct 5 ms 9680 KB Output is correct
23 Correct 5 ms 9680 KB Output is correct
24 Correct 5 ms 9680 KB Output is correct
25 Correct 5 ms 9680 KB Output is correct
26 Correct 5 ms 9680 KB Output is correct
27 Correct 5 ms 9720 KB Output is correct
28 Correct 5 ms 9680 KB Output is correct
29 Correct 5 ms 9740 KB Output is correct
30 Correct 7 ms 9680 KB Output is correct
31 Correct 5 ms 9680 KB Output is correct
32 Correct 5 ms 9680 KB Output is correct
33 Correct 5 ms 9648 KB Output is correct
34 Correct 6 ms 9680 KB Output is correct
35 Correct 5 ms 9680 KB Output is correct
36 Correct 5 ms 9680 KB Output is correct
37 Correct 5 ms 9680 KB Output is correct
38 Correct 6 ms 9680 KB Output is correct
39 Correct 5 ms 9680 KB Output is correct
40 Correct 5 ms 9680 KB Output is correct
41 Correct 7 ms 9692 KB Output is correct
42 Correct 6 ms 9680 KB Output is correct
43 Correct 6 ms 9752 KB Output is correct
44 Correct 5 ms 9680 KB Output is correct
45 Correct 5 ms 9680 KB Output is correct
46 Correct 19 ms 11992 KB Output is correct
47 Correct 19 ms 13516 KB Output is correct
48 Correct 22 ms 13536 KB Output is correct
49 Correct 20 ms 13908 KB Output is correct
50 Correct 20 ms 13888 KB Output is correct
51 Correct 28 ms 13912 KB Output is correct
52 Correct 18 ms 13904 KB Output is correct
53 Correct 17 ms 12252 KB Output is correct
54 Correct 18 ms 12252 KB Output is correct
55 Correct 16 ms 12252 KB Output is correct
56 Correct 17 ms 12248 KB Output is correct
57 Correct 20 ms 13524 KB Output is correct
58 Correct 20 ms 13908 KB Output is correct
59 Correct 19 ms 13908 KB Output is correct
60 Correct 16 ms 12252 KB Output is correct
61 Correct 17 ms 12312 KB Output is correct
62 Correct 19 ms 13520 KB Output is correct
63 Correct 19 ms 13908 KB Output is correct
64 Correct 23 ms 13916 KB Output is correct
65 Correct 19 ms 12260 KB Output is correct
66 Correct 17 ms 12256 KB Output is correct
67 Correct 22 ms 13136 KB Output is correct
68 Correct 19 ms 13540 KB Output is correct
69 Correct 20 ms 13528 KB Output is correct
70 Correct 19 ms 13904 KB Output is correct
71 Correct 21 ms 13908 KB Output is correct
72 Correct 23 ms 13916 KB Output is correct
73 Correct 21 ms 13912 KB Output is correct
74 Correct 17 ms 12240 KB Output is correct
75 Correct 16 ms 12268 KB Output is correct
76 Correct 16 ms 12272 KB Output is correct
77 Correct 25 ms 12256 KB Output is correct
78 Execution timed out 4037 ms 13520 KB Time limit exceeded
79 Halted 0 ms 0 KB -