Submission #1070704

# Submission time Handle Problem Language Result Execution time Memory
1070704 2024-08-22T16:58:25 Z Boas Radio Towers (IOI22_towers) C++17
0 / 100
4000 ms 15028 KB
#include "towers.h"

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

template <typename T1, typename T2>
using indexed_map = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using indexed_set = indexed_map<T, null_type>;

#define loop(x, i) for (int i = 0; i < (x); i++)
#define loop1(x, i) for (int i = 1; i <= (x); i++)
#define rev(x, i) for (int i = (int)(x) - 1; i >= 0; i--)
#define itloop(x) for (auto it = begin(x); x != end(x); it++)
#define itrev(x) for (auto it = rbegin(x); x != rend(x); it++)
#define INF ((int64_t)(4e18 + 1))
#define INF32 ((int32_t)(2e9 + 1))
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define removeIn(x, l) l.erase(find(ALL(l), x))
#define pb push_back
#define sz(x) (int)(x).size()
#define F first
#define S second
#define var const auto &
#define foreach(l) for (var e : l)

typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vii> vvii;
typedef vector<viii> vviii;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;
typedef vector<si> vsi;
typedef vector<sii> vsii;
typedef vector<vsi> vvsi;
typedef vector<string> vstr;
typedef vector<vector<string>> vvstr;
typedef vector<bool> vb;
typedef vector<vb> vvb;

vi h;
vii minTree, maxTree;
vii dp, maxDP;
vvi p;
int n;
int treeN = 1;
int lastD = -1;

void init(int N, vi H)
{
  h = H;
  n = N;
  while (treeN < N)
    treeN *= 2;
  minTree = vii(treeN * 2, {1e9, 1e9});
  maxTree = vii(treeN * 2, {0, -1e9});
  loop(n, i)
  {
    minTree[treeN + i] = {H[i], i};
    maxTree[treeN + i] = {H[i], -i};
  }
  rev(treeN, i)
  {
    minTree[i] = min(minTree[2 * i + 1], minTree[2 * i]);
    maxTree[i] = max(maxTree[2 * i + 1], maxTree[2 * i]);
  }
}

ii combine(ii a, ii b, bool minOp)
{
  if (minOp)
    return min(a, b);
  return max(a, b);
}

// v, ix
ii query(int i, int l, int r, int ql, int qr, bool minOp)
{
  if (r < ql || qr < l)
    return {1e9 * minOp, 1e9 * minOp};
  int m = l + (r - l) / 2;
  if (ql <= l && r <= qr)
  {
    if (minOp)
      return minTree[i];
    return maxTree[i];
  }
  return combine(query(2 * i, l, m, ql, qr, minOp),
                 query(2 * i + 1, m + 1, r, ql, qr, minOp), minOp);
}

void calcDP(int D)
{
  lastD = D;
  dp = maxDP = vii(n + 1, {1, -1});
  loop(n + 1, i)
  {
    dp[i] = maxDP[i] = {1, -i};
  }
  p = vvi(20, vi(n, -1));
  for (int i = n - 1; i >= 0; i--)
  {
    int maxSoFar = 0;
    for (int j = i + 1; j < n; j++)
    {
      maxSoFar = max(maxSoFar, h[j]);
      if (maxSoFar - max(h[i], h[j]) >= D)
      {
        dp[i] = {maxDP[j].first + 1, -i};
        p[0][i] = j;
        break;
      }
    }
    if (p[0][i] == -1)
      p[0][i] = i;
    maxDP[i] = max(dp[i], maxDP[i + 1]);
  }
  loop1(19, x)
  {
    loop(n, i)
    {
      p[x][i] = p[x - 1][p[x - 1][i]];
    }
  }
}

int getParent(int i, int k)
{
  loop(20, x)
  {
    if ((1 << x) & k)
    {
      i = p[x][i];
    }
  }
  return i;
}

int max_towers(int L, int R, int D)
{
  if (lastD != D)
  {
    calcDP(D);
  }
  auto [hi, i] = maxDP[L];
  i *= -1;
  hi--;
  int lo = 0;
  while (hi > lo)
  {
    int m = lo + (hi - lo + 1) / 2;
    int j = getParent(i, m);
    if (j == R)
    {
      lo = hi = m;
    }
    if (j > R)
    {
      hi = m - 1;
    }
    else
      lo = m;
  }
  return maxDP[i].first - (maxDP[getParent(i, lo)].first - 1);
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4030 ms 13500 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 2 ms 852 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Incorrect 3 ms 600 KB 1st lines differ - on the 1st token, expected: '34', found: '32'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 2 ms 852 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Incorrect 3 ms 600 KB 1st lines differ - on the 1st token, expected: '34', found: '32'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 606 ms 15028 KB 14th lines differ - on the 1st token, expected: '16602', found: '16601'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4059 ms 5848 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 2 ms 852 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Incorrect 3 ms 600 KB 1st lines differ - on the 1st token, expected: '34', found: '32'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4030 ms 13500 KB Time limit exceeded
2 Halted 0 ms 0 KB -