Submission #1047516

#TimeUsernameProblemLanguageResultExecution timeMemory
1047516SN0WM4NRainforest Jumps (APIO21_jumps)C++14
33 / 100
4073 ms10620 KiB
#include "jumps.h" #include <bits/stdc++.h> using namespace std; #define F first #define S second vector<int> v; vector<int> m_sig, m_prev; class FT{ private: int n; vector<int> v; public: FT(int _n) { n = _n; v.resize(n + 10); } void update(int p, int x) { p ++; while (p <= n) { v[p] += x; p += p & -p; } } int query(int p) { p ++; int res = 0; while (0 < p) { res += v[p]; p -= p & -p; } return res; } int query(int l, int r) { return query(r) - query(l - 1); } }; void init(int N, std::vector<int> H) { v = H; m_sig.resize(N); m_prev.resize(N); vector<pair<int, int>> pos(N); for (int i = 0; i < N; i ++) pos[i] = {H[i], i}; stable_sort(pos.rbegin(), pos.rend()); for (int i = 0; i < N; i ++) cerr << "{" << pos[i].F << " " << pos[i].S << "} "; cerr << "\n"; FT aux(N + 1); for (int i = 0; i < N; i ++) { m_prev[pos[i].S] = pos[i].S; m_sig[pos[i].S] = pos[i].S; int l = 0, r = pos[i].S; while (l <= r) { int mid = (l + r) / 2; if (aux.query(mid, pos[i].S)) { m_prev[pos[i].S] = mid; l = mid + 1; } else { r = mid - 1; } } l = pos[i].S, r = N - 1; while (l <= r) { int mid = (l + r) / 2; if (aux.query(pos[i].S, mid)) { m_sig[pos[i].S] = mid; r = mid - 1; } else { l = mid + 1; } } aux.update(pos[i].S, 1); } } int minimum_jumps(int A, int B, int C, int D) { vector<int> vis(v.size(), 1e9); queue<pair<int, int>> q; for (int i = A; i <= B; i ++) q.push({i, 0}); while (!q.empty()) { auto [x, d] = q.front(); q.pop(); if (vis[x] <= d) continue; if (C <= x && x <= D) return d; vis[x] = d; q.push({m_sig[x], d + 1}); q.push({m_prev[x], d + 1}); } return -1; }

Compilation message (stderr)

jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:104:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  104 |                 auto [x, d] = q.front();
      |                      ^
#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...