Submission #569155

#TimeUsernameProblemLanguageResultExecution timeMemory
569155Soumya1Rainforest Jumps (APIO21_jumps)C++17
Compilation error
0 ms0 KiB
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
const int mxN = 2e5 + 5;
const int lg = 20;
int l[lg][mxN], r[lg][mxN];
int h[mxN];
void init(int n, vector<int> H) {
  stack<int> s;
  for (int i = 0; i < n; i++) h[i + 1] = H[i];
  for (int i = 1; i <= n; i++) {
    while (!s.empty() && h[s.top()] <= h[i]) {
      l[s.top()] = i;
      s.pop();
    }
    s.push(i);
  }
  while (!s.empty()) s.pop();
  for (int i = n; i >= 1; i--) {
    while (!s.empty() && h[s.top()] <= h[i]) {
      r[s.top()] = i;
      s.pop();
    }
    r[0][i] = (s.empty() ? 0 : s.top());
    s.push(i);
  }
  for (int i = 1; i <= n; i++) {
    if (h[l[0][i]] > h[r[0][i]]) swap(l[0][i], r[0][i]);
  }
  h[0] = 1e9;
  for (int j = 1; j < lg; j++) {
    for (int i = 1; i <= n; i++) {
      l[j][i] = l[j - 1][l[j - 1][i]];
      r[j][i] = r[j - 1][r[j - 1][i]];
    }
  }
}
int minimum_jumps(int a, int b, int c, int d) {
  int ans = 0;
  for (int j = lg - 1; j >= 0; j--) {
    if (h[r[j][a]] <= h[c]) {
      a = r[j][a];
      ans += (1 << j);
    }
  }
  for (int j = lg - 1; j >= 0; j--) {
    if (h[l[j][a]] <= h[c]) {
      a = l[j][a];
      ans += (1 << j);
    }
  }
  if (a == c) return ans;
  return -1;
}

Compilation message (stderr)

jumps.cpp: In function 'void init(int, std::vector<int>)':
jumps.cpp:13:18: error: incompatible types in assignment of 'int' to 'int [200005]'
   13 |       l[s.top()] = i;
      |       ~~~~~~~~~~~^~~
jumps.cpp:21:18: error: incompatible types in assignment of 'int' to 'int [200005]'
   21 |       r[s.top()] = i;
      |       ~~~~~~~~~~~^~~