Submission #670369

# Submission time Handle Problem Language Result Execution time Memory
670369 2022-12-08T19:23:13 Z MilosMilutinovic Radio Towers (IOI22_towers) C++17
0 / 100
553 ms 23684 KB
#include "towers.h"

#include <bits/stdc++.h>

using namespace std;

const int MAX = 100005;
const int MAXN = 20 * MAX;

int n, root[MAX], tsz, st[MAXN], ls[MAXN], rs[MAXN];

void Modify(int& v, int p, int l, int r, int i, int x) {
  v = ++tsz;
  ls[v] = ls[p];
  rs[v] = rs[p];
  st[v] = st[p] + x;
  if (l == r) {
    return;
  }
  int mid = l + r >> 1;
  if (i <= mid) {
    Modify(ls[v], ls[p], l, mid, i, x);
  } else {
    Modify(rs[v], rs[p], mid + 1, r, i, x);
  }
}

int Query(int v, int l, int r, int ll, int rr) {
  if (l > r || l > rr || r < ll) {
    return 0;
  }
  if (ll <= l && r <= rr) {
    return st[v];
  }
  int mid = l + r >> 1;
  return Query(ls[v], l, mid, ll, rr) + Query(rs[v], mid + 1, r, ll, rr);
}

vector<pair<int, int>> qp;

void init(int n, std::vector<int> h) {
  ::n = n;
  vector<int> L(n);
  vector<int> R(n);
  vector<int> stk;
  for (int i = 0; i < n; i++) {
    while (!stk.empty() && h[i] < h[stk.back()]) {
      stk.pop_back();
    }
    L[i] = (stk.empty() ? -1 : stk.back());
    stk.push_back(i);
  }
  stk.clear();
  for (int i = n - 1; i >= 0; i--) {
    while (!stk.empty() && h[i] < h[stk.back()]) {
      stk.pop_back();
    }
    R[i] = (stk.empty() ? -1 : stk.back());
    stk.push_back(i);
  }
  for (int i = 0; i < n; i++) {
    if (L[i] == -1 || R[i] == -1) {
      continue;
    }
    int mx = max(h[L[i]], h[R[i]]);
    qp.push_back({h[i] - mx, i});
  }
  sort(qp.begin(), qp.end());
  int prv = 0;
  for (int i = 0; i < (int) qp.size(); i++) {
    Modify(root[i], prv, 0, n - 1, qp[i].second, +1);
    prv = root[i];
  }
}

int max_towers(int L, int R, int D) {
  int pos = lower_bound(qp.begin(), qp.end(), make_pair(D, -1)) - qp.begin();
  return Query(root[pos], 0, n - 1, L, R) + 1;
}

Compilation message

towers.cpp: In function 'void Modify(int&, int, int, int, int, int)':
towers.cpp:20:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |   int mid = l + r >> 1;
      |             ~~^~~
towers.cpp: In function 'int Query(int, int, int, int, int)':
towers.cpp:35:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |   int mid = l + r >> 1;
      |             ~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 391 ms 14020 KB 12th lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '13', found: '23'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '13', found: '23'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 553 ms 23684 KB 1st lines differ - on the 1st token, expected: '11903', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 296 ms 5448 KB 1st lines differ - on the 1st token, expected: '7197', found: '11745'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '13', found: '23'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 391 ms 14020 KB 12th lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -