結果

問題 No.878 Range High-Element Query
ユーザー t98slidert98slider
提出日時 2023-10-21 11:48:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 4,130 ms
コンパイル使用メモリ 231,176 KB
実行使用メモリ 11,588 KB
最終ジャッジ日時 2023-10-21 11:48:25
合計ジャッジ時間 7,165 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,596 KB
testcase_01 AC 4 ms
4,860 KB
testcase_02 AC 4 ms
4,860 KB
testcase_03 AC 4 ms
4,860 KB
testcase_04 AC 3 ms
4,860 KB
testcase_05 AC 3 ms
4,860 KB
testcase_06 AC 3 ms
4,860 KB
testcase_07 AC 3 ms
4,860 KB
testcase_08 AC 3 ms
4,860 KB
testcase_09 AC 4 ms
4,860 KB
testcase_10 AC 3 ms
4,596 KB
testcase_11 AC 65 ms
10,220 KB
testcase_12 AC 52 ms
10,796 KB
testcase_13 AC 52 ms
8,896 KB
testcase_14 AC 41 ms
8,216 KB
testcase_15 AC 51 ms
10,364 KB
testcase_16 AC 66 ms
11,444 KB
testcase_17 AC 72 ms
11,588 KB
testcase_18 AC 71 ms
11,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;

int op(int l, int r){return min(l, r);}
int e(){return 1 << 30;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, Q, M = 100005, l, r, g;
    cin >> N >> Q;
    vector<int> a(N);
    g = __lg(N);
    vector<vector<int>> dp(g + 1, vector<int>(N + 1, N));
    for(auto &&v : a) cin >> v;
    atcoder::segtree<int, op, e> seg(vector<int>(M, N));
    for(int i = N - 1; i >= 0; i--){
        dp[0][i] = seg.prod(a[i] + 1, M);
        seg.set(a[i], i);
    }
    for(int i = 0; i < g; i++){
        for(int j = 0; j < N; j++){
            dp[i + 1][j] = dp[i][dp[i][j]];
        }
    }
    while(Q--){
        cin >> l >> l >> r;
        l--;
        int ans = 0;
        for(int i = g; i >= 0; i--){
            if(dp[i][l] < r){
                l = dp[i][l];
                ans |= 1 << i;
            }
        }
        cout << ++ans << '\n';
    }
}
0