結果
問題 | No.878 Range High-Element Query |
ユーザー |
![]() |
提出日時 | 2019-09-07 12:18:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 59 ms / 2,000 ms |
コード長 | 1,232 bytes |
コンパイル時間 | 827 ms |
コンパイル使用メモリ | 82,444 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-06-26 08:00:24 |
合計ジャッジ時間 | 2,283 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int k = 1, t = 1; while (t * 2 <= n - 1) t *= 2, k++; vector<pair<int, int>> b(n); vector<vector<int>> c(k, vector<int>(n)); auto it = b.end(); for (int i = n - 1; i >= 0; i--) { pair<int, int> t = { a[i], i }; it = upper_bound(it, b.end(), t); c[0][i] = it == b.end() ? n : it->second; *--it = t; } for (int l = 1; l < k; l++) { for (int i = 0; i < n; i++) { int j = c[l - 1][i]; c[l][i] = j < n ? c[l - 1][j] : n; } } for (int h = 0; h < q; h++) { int t, l, r; cin >> t >> l >> r; l--; int i = l, a = 1; for (int l = k - 1; l >= 0; l--) { int t = c[l][i]; if (t < r) { i = t; a += 1 << l; } } cout << a << '\n'; } return 0; }