Submission #566870

# Submission time Handle Problem Language Result Execution time Memory
566870 2022-05-23T04:54:15 Z amunduzbaev Rainforest Jumps (APIO21_jumps) C++17
27 / 100
1223 ms 77372 KB
#include "jumps.h"

#ifndef EVAL
#include "stub.cpp"
#endif

#include "bits/stdc++.h"
using namespace std;

const int B = 205;
const int N = 2e5 + 5;
const int lg = 18;
int mx[N][lg], mn[N][lg], h[N], pos[N];
int lx[N], rx[N], prec[N/B][N];

struct ST{
	vector<int> tree[N << 2];
	void build(int lx = 0, int rx = N, int x = 1){
		if(lx == rx) { tree[x].push_back(h[lx]); return; }
		int m = (lx + rx) >> 1;
		build(lx, m, x << 1);
		build(m + 1, rx, x << 1 | 1);
		tree[x].insert(tree[x].end(), tree[x<<1].begin(), tree[x<<1].end());
		tree[x].insert(tree[x].end(), tree[x<<1|1].begin(), tree[x<<1|1].end());
		sort(tree[x].begin(), tree[x].end());
	}
	
	int get(int l, int r, int v, int lx = 0, int rx = N, int x = 1){
		if(lx > r || rx < l) return -1;
		if(lx >= l && rx <= r){
			auto it = lower_bound(tree[x].begin(), tree[x].end(), v);
			if(it == tree[x].begin()) return -1;
			return *--it;
		} int m = (lx + rx) >> 1;
		return max(get(l, r, v, lx, m, x<<1), get(l, r, v, m+1, rx, x<<1|1));
	}
}tree;

void init(int n, vector<int> H){
	for(int i=0;i<n;i++){
		h[i] = H[i];
		pos[h[i]] = i;
	}
	vector<int> ss;
	for(int i=0;i<n;i++){
		while(!ss.empty() && h[ss.back()] < h[i]) ss.pop_back();
		if(!ss.empty()) lx[i] = ss.back();
		else lx[i] = n;
		ss.push_back(i);
	} ss.clear();
	for(int i=n-1;~i;i--){
		while(!ss.empty() && h[ss.back()] < h[i]) ss.pop_back();
		if(!ss.empty()) rx[i] = ss.back();
		else rx[i] = n;
		ss.push_back(i);
	} ss.clear();
	h[n] = N;
	tree.build();
	for(int i=0;i<n;i++){
		if(h[lx[i]] < h[rx[i]]){
			swap(lx[i], rx[i]);
		} 
		mn[i][0] = rx[i];
		mx[i][0] = lx[i];
	}
	mn[n][0] = mx[n][0] = n;
	//~ for(int i=0;i<n;i++) cout<<mn[i][0]<<" ";
	//~ cout<<"\n";
	//~ for(int i=0;i<n;i++) cout<<mx[i][0]<<" ";
	//~ cout<<"\n";
	
	for(int j=1;j<lg;j++){
		for(int i=0;i<=n;i++){
			mn[i][j] = mn[mn[i][j-1]][j-1];
			mx[i][j] = mx[mx[i][j-1]][j-1];
		}
	}
	
	
}

int check(int a, int c){
	int res = 0;
	for(int i=lg-1;~i;i--){
		if(h[mx[a][i]] <= h[c]){
			//~ cout<<mx[a][i]<<" "<<h[mx[a][i]]<<" "<<h[c]<<"\n";
			//~ cout<<i<<"\n";
			a = mx[a][i], res += (1 << i);
		}
	}
	for(int i=lg-1;~i;i--){
		if(h[mn[a][i]] <= h[c]){
			//~ cout<<mx[a][i]<<" "<<h[mx[a][i]]<<" "<<h[c]<<"\n";
			a = mn[a][i], res += (1 << i);
		}
	}
	
	if(a != c) return -1;
	return res;
}

int minimum_jumps(int a, int b, int c, int d) {
	//~ int res = N;
	a = tree.get(a, b, h[c]);
	if(a == -1) return -1;
	return check(pos[a], c);
}

/*

7 2
3 2 1 6 4 5 7
4 4 6 6
0 1 2 2

*/
# Verdict Execution time Memory Grader output
1 Correct 84 ms 43624 KB Output is correct
2 Correct 87 ms 43632 KB Output is correct
3 Correct 274 ms 70392 KB Output is correct
4 Correct 1223 ms 77180 KB Output is correct
5 Correct 1053 ms 60216 KB Output is correct
6 Correct 1194 ms 77372 KB Output is correct
7 Correct 1008 ms 66556 KB Output is correct
8 Correct 1158 ms 77220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 90 ms 43592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 90 ms 43592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 43536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 94 ms 43596 KB Output is correct
2 Correct 107 ms 43576 KB Output is correct
3 Correct 91 ms 43576 KB Output is correct
4 Correct 337 ms 58280 KB Output is correct
5 Correct 1108 ms 76092 KB Output is correct
6 Correct 724 ms 48636 KB Output is correct
7 Correct 1079 ms 76084 KB Output is correct
8 Correct 650 ms 54476 KB Output is correct
9 Correct 989 ms 76088 KB Output is correct
10 Correct 937 ms 77308 KB Output is correct
11 Correct 1067 ms 77244 KB Output is correct
12 Correct 1045 ms 77180 KB Output is correct
13 Correct 1016 ms 76148 KB Output is correct
14 Correct 1024 ms 76536 KB Output is correct
15 Correct 838 ms 77184 KB Output is correct
16 Correct 952 ms 77200 KB Output is correct
17 Correct 90 ms 43536 KB Output is correct
18 Correct 87 ms 43616 KB Output is correct
19 Correct 89 ms 43604 KB Output is correct
20 Correct 93 ms 43656 KB Output is correct
21 Correct 93 ms 43536 KB Output is correct
22 Correct 97 ms 43616 KB Output is correct
23 Correct 92 ms 43612 KB Output is correct
24 Correct 90 ms 43652 KB Output is correct
25 Correct 95 ms 43712 KB Output is correct
26 Correct 94 ms 43632 KB Output is correct
27 Correct 104 ms 43604 KB Output is correct
28 Correct 104 ms 43652 KB Output is correct
29 Correct 106 ms 43656 KB Output is correct
30 Correct 110 ms 43612 KB Output is correct
31 Correct 113 ms 43692 KB Output is correct
32 Correct 89 ms 43524 KB Output is correct
33 Correct 185 ms 62304 KB Output is correct
34 Correct 266 ms 76104 KB Output is correct
35 Correct 157 ms 77156 KB Output is correct
36 Correct 238 ms 75996 KB Output is correct
37 Correct 191 ms 76512 KB Output is correct
38 Correct 174 ms 77256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 43596 KB Output is correct
2 Correct 107 ms 43576 KB Output is correct
3 Correct 91 ms 43576 KB Output is correct
4 Correct 337 ms 58280 KB Output is correct
5 Correct 1108 ms 76092 KB Output is correct
6 Correct 724 ms 48636 KB Output is correct
7 Correct 1079 ms 76084 KB Output is correct
8 Correct 650 ms 54476 KB Output is correct
9 Correct 989 ms 76088 KB Output is correct
10 Correct 937 ms 77308 KB Output is correct
11 Correct 1067 ms 77244 KB Output is correct
12 Correct 1045 ms 77180 KB Output is correct
13 Correct 1016 ms 76148 KB Output is correct
14 Correct 1024 ms 76536 KB Output is correct
15 Correct 838 ms 77184 KB Output is correct
16 Correct 952 ms 77200 KB Output is correct
17 Correct 90 ms 43536 KB Output is correct
18 Correct 87 ms 43616 KB Output is correct
19 Correct 89 ms 43604 KB Output is correct
20 Correct 93 ms 43656 KB Output is correct
21 Correct 93 ms 43536 KB Output is correct
22 Correct 97 ms 43616 KB Output is correct
23 Correct 92 ms 43612 KB Output is correct
24 Correct 90 ms 43652 KB Output is correct
25 Correct 95 ms 43712 KB Output is correct
26 Correct 94 ms 43632 KB Output is correct
27 Correct 104 ms 43604 KB Output is correct
28 Correct 104 ms 43652 KB Output is correct
29 Correct 106 ms 43656 KB Output is correct
30 Correct 110 ms 43612 KB Output is correct
31 Correct 113 ms 43692 KB Output is correct
32 Correct 89 ms 43524 KB Output is correct
33 Correct 185 ms 62304 KB Output is correct
34 Correct 266 ms 76104 KB Output is correct
35 Correct 157 ms 77156 KB Output is correct
36 Correct 238 ms 75996 KB Output is correct
37 Correct 191 ms 76512 KB Output is correct
38 Correct 174 ms 77256 KB Output is correct
39 Correct 90 ms 43528 KB Output is correct
40 Correct 93 ms 43652 KB Output is correct
41 Correct 90 ms 43544 KB Output is correct
42 Correct 370 ms 58252 KB Output is correct
43 Correct 1082 ms 76216 KB Output is correct
44 Correct 726 ms 48568 KB Output is correct
45 Correct 948 ms 76092 KB Output is correct
46 Correct 665 ms 54548 KB Output is correct
47 Correct 1053 ms 76116 KB Output is correct
48 Correct 957 ms 77176 KB Output is correct
49 Correct 1040 ms 77116 KB Output is correct
50 Correct 1012 ms 77092 KB Output is correct
51 Correct 1144 ms 76092 KB Output is correct
52 Correct 1074 ms 76508 KB Output is correct
53 Correct 1020 ms 77244 KB Output is correct
54 Correct 829 ms 77244 KB Output is correct
55 Correct 87 ms 43544 KB Output is correct
56 Incorrect 323 ms 75972 KB Output isn't correct
57 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 84 ms 43624 KB Output is correct
2 Correct 87 ms 43632 KB Output is correct
3 Correct 274 ms 70392 KB Output is correct
4 Correct 1223 ms 77180 KB Output is correct
5 Correct 1053 ms 60216 KB Output is correct
6 Correct 1194 ms 77372 KB Output is correct
7 Correct 1008 ms 66556 KB Output is correct
8 Correct 1158 ms 77220 KB Output is correct
9 Incorrect 90 ms 43592 KB Output isn't correct
10 Halted 0 ms 0 KB -