Submission #429978

#TimeUsernameProblemLanguageResultExecution timeMemory
429978hhhhauraRainforest Jumps (APIO21_jumps)C++14
48 / 100
1968 ms91284 KiB
    #define wiwihorz
    #include "jumps.h"
    #include <bits/stdc++.h>
    #pragma GCC optimize("Ofast")
    #pragma loop-opt(on)
     
    #define rep(i, a, b) for(int i = a; i <= b; i++)
    #define rrep(i, a, b) for(int i = b; i >= a; i--)
    #define ceil(a, b) ((a + b - 1) / (b))
    #define all(x) x.begin(), x.end()
     
    #define MOD 1000000007
    #define eps (1e-9)
    #define INF 1000000000
    using namespace std;
     
    #define lld long double
    #define pii pair<int, int>
    #define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
     
    #ifdef wiwihorz
    #define print(a...) kout("[" + string(#a) + "] = ", a)
    void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L; }
    void kout() {cerr << endl; }
    template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...);}
    #else
    #define print(...) 0
    #define vprint(...) 0
    #endif
    int n, lg;
    vector<int> L, R, h, t;
    vector<vector<int>> l, r, to;
    vector<vector<pii>> sp;
    int query(int L, int R) {
    	if(L > R) return -1;
    	int cur = 31 - __builtin_clz(R - L + 1);
    	pii ans = max(sp[cur][L], sp[cur][R - (1 << cur) + 1]);
    	return ans.second;
    }
    void init(int N, vector<int> H) {
    	n = N, lg = 32 - __builtin_clz(n);
    	set<int> s; vector<int> a(n, 0);
    	L.assign(n + 2, 0);
    	R.assign(n + 2, 0);
    	t.assign(n + 2, 0);
    	h.assign(n + 2, 0);
    	h[0] = h[n + 1] = INF;
    	rep(i, 0, n - 1) h[i + 1] = H[i];
    	rep(i, 1, n) a[i - 1] = i;
    	sort(all(a), [](int x, int y) { return h[x] > h[y]; });
    	s.insert(n + 1), s.insert(0);
    	for(auto i : a) {
    		auto it = s.lower_bound(i);
    		int x = *it, y = *prev(it);
    		if(h[x] < h[y]) swap(x, y);
    		R[i] = x, L[i] = y, t[i] = *it;
    		s.insert(i);
    	}
    	l.assign(lg + 1, vector<int>(n + 2, 0));
    	r.assign(lg + 1, vector<int>(n + 2, 0));
    	sp.assign(lg + 1, vector<pii>(n + 2, {0, 0}));
    	to.assign(lg + 1, vector<int>(n + 2, 0));
    	L[0] = R[0] = 0, L[n + 1] = R[n + 1] = n + 1;
    	rep(i, 0, n + 1) {
    		sp[0][i] = {h[i], i};
    		l[0][i] = L[i];
    		r[0][i] = R[i];
    		to[0][i] = t[i];
    	}
    	rep(i, 1, lg) rep(j, 0, n + 1) {
    		sp[i][j] = max(sp[i - 1][j], sp[i - 1][j + (1 << (i - 1))]);
    		l[i][j] = l[i - 1][l[i - 1][j]];
    		r[i][j] = r[i - 1][r[i - 1][j]];
    		to[i][j] = to[i - 1][to[i - 1][j]];
    	}
    	return;
    }
    /*
    7 3
    3 2 1 6 4 5 7
    4 4 6 6
    1 3 5 6
    0 1 2 2 
    */
    int minimum_jumps(int A, int B, int C, int D) {
    	A ++ ,B ++ , C ++, D ++;	
    	int st, ll = A - 1, rr = B + 1, ans = 0, mx;
    	mx = query(C, D);
    	while(rr - ll > 1) {
    		int mid = (ll + rr) / 2;
    		int x = query(mid, B);
    		if(h[mx] < h[x]) ll = mid;
    		else rr = mid;
    	} 
    	st = query(rr, B);
    	if(st == -1) return -1;
    	rrep(i, 0, lg) {
    		if(h[r[i][st]] < h[mx] && r[i][st] < C && l[i][st] < C)
    			st = r[i][st], ans += (1 << i);
    	}
    	if(r[0][st] <= D && r[0][st] >= C) return ans + 1;
    	rrep(i, 0, lg) if(h[to[i][st]] <= h[mx]) {
    		if(to[i][st] < C) st = to[i][st], ans += (1 << i);
    	}
    	st = to[0][st];
    	if(st <= D && st >= C) return ans + 1;
    	return -1;
    }

Compilation message (stderr)

jumps.cpp:5: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    5 |     #pragma loop-opt(on)
      | 
jumps.cpp:23:17: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   23 |     void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L; }
      |                 ^~~~
jumps.cpp:23:25: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   23 |     void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L; }
      |                         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...