제출 #986561

#제출 시각아이디문제언어결과실행 시간메모리
986561ZHIRDILBILDIZ밀림 점프 (APIO21_jumps)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "jumps.h" #define fi first #define se second #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> using namespace std; const int N = 2e5 + 10; int pw[N]; int rg[N][20]; int lf[N][20]; int mx[N][20]; int path[N][20]; vector<int> _h; void build_sparce (vector<int> h) { for (int i = 2; i <= h.size(); ++i) pw[i] = pw[i >> 1] + 1; for (int i = 0; i < h.size(); ++i) mx[i][0] = h[i]; for (int i = 1; i < 20; ++i) for (int j = 0; j <= (int)h.size() - (1 << i); ++j) mx[j][i] = max(mx[j][i - 1], mx[j + (1 << (i - 1))][i - 1]); } int get_max (int l, int r) { if (l > r) swap(l, r); int x = pw[r - l + 1]; return max(mx[l][x], mx[r - (1 << x) + 1][x]); } void init (int n, vector<int> h) { _h = h; build_sparce(h); for (int i = 0; i < n; ++i) { int l = i, r = n; lf[i][0] = rg[i][0] = i; while (l + 1 < r) { int mid = (l + r) / 2; if (get_max(i, mid) == h[i]) l = mid; else r = mid; } if (r != n) rg[i][0] = r; l = -1, r = i; while (l + 1 < r) { int mid = (l + r) / 2; if (get_max(mid, i) == h[i]) r = mid; else l = mid; } if (l != -1) lf[i][0] = l; if (h[lf[i][0]] > h[rg[i][0]]) path[i][0] = lf[i][0]; else path[i][0] = rg[i][0]; } for (int i = 1; i < 20; ++i) for (int j = 0; j < n; ++j) { lf[j][i] = lf[lf[j][i - 1]][i - 1]; rg[j][i] = rg[rg[j][i - 1]][i - 1]; path[j][i] = path[path[j][i - 1]][i - 1]; } } int minimum_jumps(int a, int b, int c, int d) { int vall = get_max(c, d); int vall1 = get_max(b, c - 1); for (int i = 19; i >= 0; --i) if (a <= lf[b][i] && _h[lf[b][i]] <= vall) b = lf[b][i]; int kol = 0; for (int i = 19; i >= 0; --i) if (_h[path[b][i]] <= vall1) { b = path[b][i]; kol += (1 << i); } if (c <= rg[b][0] && rg[b][0] <= d) return kol + 1; if (_h[path[b][0]] < mx) b = path[b][0], ++kol; for (int i = 19; i >= 0; --i) if (rg[b][i] < c) { b = rg[b][i]; kol += (1 << i); } if (c <= rg[b][0] && rg[b][0] <= d) return kol + 1; return -1; } // signed main () { // // ios_base::sync_with_stdio(0); // // cin.tie(0), cout.tie(0); // int n; // cin >> n; // vector<int> h(n); // for (int i = 0; i < n; ++i) cin >> h[i]; // init(n, h); // int q; // cin >> q; // while (q--) { // int a, b, c, d; // cin >> a >> b >> c >> d; // cout << minimum_jumps(a, b, c, d) << '\n'; // } // return 0; // }

컴파일 시 표준 에러 (stderr) 메시지

jumps.cpp: In function 'void build_sparce(std::vector<int>)':
jumps.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i = 2; i <= h.size(); ++i) pw[i] = pw[i >> 1] + 1;
      |                     ~~^~~~~~~~~~~
jumps.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (int i = 0; i < h.size(); ++i) mx[i][0] = h[i];
      |                     ~~^~~~~~~~~~
jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:91:24: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   91 |     if (_h[path[b][0]] < mx)