Submission #430079

#TimeUsernameProblemLanguageResultExecution timeMemory
430079hhhhauraRainforest Jumps (APIO21_jumps)C++14
100 / 100
2008 ms106940 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, hh, ll; vector<vector<int>> l, r, high, low; 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); hh.assign(n + 2, 0); ll.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); hh[i] = x, ll[i] = y; L[i] = *prev(it), R[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})); high.assign(lg + 1, vector<int>(n + 2, 0)); low.assign(lg + 1, vector<int>(n + 2, 0)); L[0] = L[n + 1] = ll[0] = hh[0] = 0; R[0] = R[n + 1] = ll[n + 1] = hh[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]; high[0][i] = hh[i]; low[0][i] = ll[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]]; high[i][j] = high[i - 1][high[i - 1][j]]; low[i][j] = low[i - 1][low[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; int ans = 0, mx, md; mx = query(C, D), md = query(B + 1, C - 1); 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 || h[md] > h[mx]) return -1; if(h[st] > h[md]) return 1; rrep(i, 0, lg) if(h[high[i][st]] <= h[md]) st = high[i][st], ans += (1 << i); if(st == md) return ans + 1; if(r[0][l[0][st]] <= D) return ans + 2; rrep(i, 0, lg) if(r[i][st] < C) st = r[i][st], ans += (1 << i); st = r[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:13: 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:21: 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...