結果
問題 | No.878 Range High-Element Query |
ユーザー |
|
提出日時 | 2019-12-19 13:15:43 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,190 bytes |
コンパイル時間 | 704 ms |
コンパイル使用メモリ | 89,992 KB |
最終ジャッジ日時 | 2024-11-14 21:59:26 |
合計ジャッジ時間 | 1,875 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:17:39: error: '::numeric_limits' has not been declared 17 | template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; | ^~~~~~~~~~~~~~ main.cpp:17:55: error: expected primary-expression before '>' token 17 | template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; | ^ main.cpp:17:61: error: no matching function for call to 'max()' 17 | template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; | ~~~~~^~ In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:50, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39, from main.cpp:1: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 254 | max(const _Tp& __a, const _Tp& __b) | ^~~ /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:254:5: note: template argument deduction/substitution failed: main.cpp:17:61: note: candidate expects 2 arguments, 0 provided 17 | template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; | ~~~~~^~ /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:300:5: n
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <map> #include <set> #include <queue> #include <stack> #include <numeric> #include <bitset> #include <cmath> static const int MOD = 1000000007; using ll = long long; using u32 = uint32_t; using namespace std; template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; template <class M> struct SegmentTree{ using T = typename M::T; int sz; vector<T> seg; explicit SegmentTree(int n) { sz = 1; while(sz < n) sz <<= 1; seg.assign(2*sz, M::e()); } void set(int k, const T &x){ seg[k + sz] = x; } void build(){ for (int i = sz-1; i > 0; --i) seg[i] = M::f(seg[2*i], seg[2*i+1]); } void update(int k, const T &x){ k += sz; seg[k] = x; while (k >>= 1) seg[k] = M::f(seg[2*k], seg[2*k+1]); } T query(int a, int b){ if(sz <= a) return M::e(); T l = M::e(), r = M::e(); for(a += sz, b += sz; a < b; a >>=1, b>>=1){ if(a & 1) l = M::f(l, seg[a++]); if(b & 1) r = M::f(seg[--b], r); } return M::f(l, r); } template<typename C> int find(int t, C &c, T &val, int k, int l, int r){ if(r-l == 1){ val = f(val, seg[k]); return c(val) ? k-sz : -1; } int m = (l+r) >> 1; if(m <= t) return find(t, c, val, (k << 1) | 1, m, r); if(t <= l && !c(val = f(val, seg[k]))) return -1; int lv = find(t, c, val, (k << 1) | 0 , l, m); if(~lv) return lv; return find(t, c, val, (k << 1) | 1, m, r); } template<typename C> int find(int t, C &c){ T val = M::e(); return find(t, c, val, 1, 0, sz); } T operator[](const int &k) const { return seg[k + sz]; } }; struct Monoid{ using T = int; static T f(T a, T b) { return min(a, b); } static T e() { return INF<int>; } }; template <class T, class U> vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); } template<class... Ts, class U> auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); } template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); } template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); } int main() { int n, q; cin >> n >> q; vector<int> v(n); for (auto &&i : v) scanf("%d", &i); auto nxt = make_v(18, n, INF<int>); SegmentTree<Monoid> seg(n); for (int i = n - 1; i >= 0; --i) { nxt[0][i] = seg.query(v[i], n); seg.update(v[i]-1, i); } for (int i = 0; i < 17; ++i) { for (int j = 0; j < n; ++j) { if(nxt[i][j] != INF<int>){ nxt[i+1][j] = nxt[i][nxt[i][j]]; } } } for (int i = 0; i < q; ++i) { int tmp, l, r; scanf("%d %d %d", &tmp, &l, &r); l--; int ans = 1; for (int j = 17; j >= 0; --j) { if(nxt[j][l] < r){ l = nxt[j][l]; ans += (1 << j); } } printf("%d\n", ans); } return 0; }