結果

問題 No.1921 Range LthKth Query
ユーザー りあんりあん
提出日時 2022-05-05 14:34:56
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,285 bytes
コンパイル時間 4,181 ms
コンパイル使用メモリ 263,992 KB
実行使用メモリ 101,264 KB
最終ジャッジ日時 2023-09-17 22:18:35
合計ジャッジ時間 12,108 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 268 ms
101,164 KB
testcase_22 WA -
evil_01.txt WA -
evil_02.txt WA -
evil_03.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

using P = pair<int, int>;
const int M = 1000000007;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n, K, L;
    cin >> n >> K >> L;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<vector<int>> kth(n + 1, vector<int>(n + 1, M));
    for (int i = 0; i < n + 1; ++i) {
        for (int l = 0, r = 0, c = 0; l < n; ++l) {
            while (r < n && c < K) {
                if (a[r] <= i) ++c;
                ++r;
            }
            if (c == K && kth[l][r] > i) {
                kth[l][r] = i;
            }
            else break;
            if (a[l] <= i) --c;
        }
    }
    for (int d = 1; d <= n; ++d) {
        for (int i = 0; i + d <= n; ++i) {
            kth[i][i + d] = min(kth[i][i + d], min(kth[i + 1][i + d], kth[i][i + d - 1]));
        }
    }
    vector<vector<int>> cnth(n + 1, vector<int>(n + 1));
    vector<vector<int>> cntw(n + 1, vector<int>(n + 1));
    for (int i = 0; i < n + 1; ++i) {
        for (int j = 0; j < n + 1; ++j) {
            if (kth[i][j] != M) {
                ++cnth[i][kth[i][j]];
                ++cntw[j][kth[i][j]];
            }
        }
    }
    for (int i = 0; i < n + 1; ++i) {
        for (int j = 0; j < n; ++j) {
            cnth[i][j + 1] += cnth[i][j];
            cntw[i][j + 1] += cntw[i][j];
        }
    }
    vector<vector<int>> lth(n + 1, vector<int>(n + 1, M));
    for (int i = 0; i < n + 1; ++i) {
        for (int l = 0, r = 0, c = 0; l < n; ++l) {
            while (r < n && c < L) {
                ++r;
                c += max(cntw[r][i] - l, 0);
            }
            if (c >= L && lth[l][r] > i) {
                lth[l][r] = i;
            }
            else break;
            c -= max(cnth[l][i] - (n - r), 0);
        }
    }
    for (int d = 1; d <= n; ++d) {
        for (int i = 0; i + d <= n; ++i) {
            lth[i][i + d] = min(lth[i][i + d], min(lth[i + 1][i + d], lth[i][i + d - 1]));
        }
    }
    int q;
    cin >> q;
    for (int _ = 0; _ < q; ++_) {
        int l, r;
        cin >> l >> r;
        --l;
        cout << lth[l][r] << '\n';
    }
    return 0;
}
0