Submission #558930

# Submission time Handle Problem Language Result Execution time Memory
558930 2022-05-09T02:35:50 Z hoanghq2004 Rainforest Jumps (APIO21_jumps) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "jumps.h"

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2e5 + 10;

int n, h[N];
int high[N][20];
int L[N][20], R[N][20];

void init(int N, std::vector<int> H) {
    n = N;
    for (int i = 1; i <= n; ++i) h[i] = H[i - 1];
    stack <int> stk;
    for (int i = 1; i <= n; ++i) {
        while (stk.size() && h[stk.top()] < h[i]) {
            R[stk.top()][0] = i;
            stk.pop();
        }
        stk.push(i);
    }
    while (stk.size()) R[stk.top()][0] = n + 1, stk.pop();
    for (int i = n; i >= 1; --i) {
        while (stk.size() && h[stk.top()] < h[i]) {
            L[stk.top()][0] = i;
            stk.pop();
        }
        stk.push(i);
    }
    while (stk.size()) L[stk.top()][0] = 0, stk.pop();
    for (int i = 1; i <= n; ++i) {
        high[i][0] = (h[L[i]][0] > h[R[i]][0] ? L[i][0] : R[i][0]);
    }
    for (int lg = 1; (1 << lg) <= n; ++lg) {
        for (int i = 1; i + (1 << lg) - 1 <= n; ++i) {
            high[i][lg] = high[high[i][lg - 1]][lg - 1];
            L[i][lg] = L[L[i][lg - 1]][lg - 1];
            R[i][lg] = R[R[i][lg - 1]][lg - 1];
        }
    }
}

int minimum_jumps(int A, int B, int C, int D) {
    ++A, ++B, ++C, ++D;
    int cost = 0;
    for (int lg = 19; lg >= 0; --lg)
        if (L[B][lg] >= A && R[L[B][lg]][0] <= D) B = L[B][lg];
    for (int lg = 19; lg >= 0; --lg)
        if (R[high[B][lg]][0] < C) B = high[B][lg], cost += (1 << lg);
    if (R[high[B][0]][0] <= D) {
        B = high[B][0];
        ++cost;
    }
    for (int lg = 19; lg >= 0; --lg)
        if (B < C && R[B][lg] <= D) {
            B = R[B][lg];
            cost += (1 << lg);
        }
    if (B > D || B < C) return -1;
    return cost;
}

//int main() {
//  int N, Q;
//  assert(2 == scanf("%d %d", &N, &Q));
//  std::vector<int> H(N);
//  for (int i = 0; i < N; ++i) {
//    assert(1 == scanf("%d", &H[i]));
//  }
//  init(N, H);
//
//  for (int i = 0; i < Q; ++i) {
//    int A, B, C, D;
//    assert(4 == scanf("%d %d %d %d", &A, &B, &C, &D));
//    printf("%d\n", minimum_jumps(A, B, C, D));
//  }
//  return 0;
//}

Compilation message

jumps.cpp: In function 'void init(int, std::vector<int>)':
jumps.cpp:41:24: error: invalid types 'int [200010][int [20]]' for array subscript
   41 |         high[i][0] = (h[L[i]][0] > h[R[i]][0] ? L[i][0] : R[i][0]);
      |                        ^
jumps.cpp:41:37: error: invalid types 'int [200010][int [20]]' for array subscript
   41 |         high[i][0] = (h[L[i]][0] > h[R[i]][0] ? L[i][0] : R[i][0]);
      |                                     ^