Submission #676373

# Submission time Handle Problem Language Result Execution time Memory
676373 2022-12-30T14:11:03 Z penguin133 Rainforest Jumps (APIO21_jumps) C++17
Compilation error
0 ms 0 KB
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
 
int n, flag;
int X[200005], Y[200005], h[200005];
int par[20][200005], par2[20][200005], par3[20][200005], par4[20][200005];
 
struct node{
	int s,e,m, val;
	node *l, *r;
	node(int _s, int _e){
		s = _s, e = _e, m = (s + e)>>1;
		if(s != e){
			l = new node(s, m);
			r = new node(m+1, e);
			val = max(l->val, r->val);
		}
		else val = h[s];
	}
	
	int query(int a, int b){
		if(s == a && b == e)return val;
		else if(b <= m)return l->query(a, b);
		else if(a > m)return r->query(a, b);
		else return max(l->query(a, m), r->query(m+1, b));
	}
	
}*root;
 
 
void init(int N, vector<int> H){
	n = N;
	stack<int>s;
	for(int i=0;i<n;i++){
		h[i] = H[i];
		while(!s.empty() && H[s.top()] < H[i])s.pop();
		X[i] = (s.empty() ? -1 : s.top());
		par3[0][i] = X[i];
		s.push(i);
	}
	flag = 1;
	for(int i=0;i<n;i++)if(H[i] != i + 1)flag= 0;
	while(!s.empty())s.pop();
	for(int i=n-1;i>=0;i--){
		while(!s.empty() && H[s.top()] < H[i])s.pop();
		Y[i] = (s.empty() ? -1 : s.top());
		par4[0][i] = Y[i];
		s.push(i);
	}
	root = new node(0, n-1);
	for(int i=0;i<n;i++){
		if(X[i] == -1 && Y[i] == -1)par[0][i] = par2[0][i] = -1;
		else if(X[i] == -1)par[0][i] = Y[i], par2[0][i] = -1;
		else if(Y[i] == -1)par[0][i] = X[i], par2[0][i] = -1;
		else par[0][i] = (H[X[i]] > H[Y[i]] ? X[i] : Y[i]), par2[0][i] = (par[0][i] == X[i] ? Y[i] : X[i]);
	}
	for(int i=1;i<=19;i++)for(int j=0;j<n;j++)par[i][j] = (par[i-1][j] == -1 ? -1 : par[i-1][par[i-1][j]]);
	for(int i=1;i<=19;i++)for(int j=0;j<n;j++)par2[i][j] = (par2[i-1][j] == -1 ? -1 : par2[i-1][par2[i-1][j]]);
	for(int i=1;i<=19;i++)for(int j=0;j<n;j++)par3[i][j] = (par3[i-1][j] == -1 ? -1 : par3[i-1][par3[i-1][j]]);
	for(int i=1;i<=19;i++)for(int j=0;j<n;j++)par4[i][j] = (par4[i-1][j] == -1 ? -1 : par4[i-1][par4[i-1][j]]);
}
 
int minimum_jumps(int a, int b, int c, int d){
 
	int ans = 0, tmp = b;
	int mx = root->query(c, d);
	int mx2 = root->query(b, c-1);
	if(mx2 > mx)return -1;
	for(int i=19;i>=0;i--)if(par3[i][tmp] != -1 && par3[i][tmp] >= a && h[par3[i][tmp]] <= mx)tmp = par3[i][tmp];
	if(par4[0][tmp] >= c)return 1;
	for(int i=19;i>=0;i--)if(par[i][tmp] != -1 && (par4[0][par[i][tmp]] != -1 && par4[0][par[i][tmp]] < c) && h[par[i][tmp]] <= mx)tmp = par[i][tmp], ans += (1 << i);
   if (par[par3[0][rmp]]<mx && par3[0][tmp]!=-1) return ans+2;
	for(int i=19;i>=0;i--)if(par4[i][tmp] != -1 && par4[i][tmp] < c && h[par4[i][tmp]] <= mx)tmp = par4[i][tmp], ans += (1 << i);
//	cerr << tmp << '\n';
	assert(par4[0][tmp] >= c && par4[0][tmp] <= d);
	return ans + 1;
	
}

Compilation message

jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:73:20: error: 'rmp' was not declared in this scope; did you mean 'tmp'?
   73 |    if (par[par3[0][rmp]]<mx && par3[0][tmp]!=-1) return ans+2;
      |                    ^~~
      |                    tmp