提出 #61608867


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
namespace po167{
template<class T, T(*op)(T, T)>
struct Sparse_table{
    int n;
    int depth;
    std::vector<std::vector<T>> val;
    void init(std::vector<T> &v){
        depth = 1;
        n = v.size();
        while ((1 << depth) <= n) depth++;
        val.resize(depth);
        val[0] = v;
        for (int i = 1; i < depth; i++){
            val[i].resize(n);
            for (int j = 0; j <= n - (1 << i); j++){
                val[i][j] = op(val[i - 1][j], val[i - 1][j + (1 << (i - 1))]);
            }
        }
    }
    Sparse_table(std::vector<T> v){
        init(v);
    }
    Sparse_table(){}
    // 0 <= l < r <= n
    // if l == r : assert
    T prod(int l, int r){
        assert(0 <= l && l < r && r <= n);
        int z=31-__builtin_clz(r-l);
        return op(val[z][l], val[z][r - (1 << z)]);
    }
};
}

int op(int a, int b){
    return max(a, b);
}


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

    int N;
    cin >> N;
    vector<int> A(N);
    for (auto &a : A) cin >> a;
    vector<int> C(N);
    {
        int r = 0;
        for (int l = 0; l < N; l++){
            while (r != N && A[l] * 2 > A[r]) r++;
            C[l] = r - l;
        }
    }
    po167::Sparse_table<int, op> S(C);
    int Q;
    cin >> Q;
    while (Q--){
        int l, r;
        cin >> l >> r;
        l--;
        int L = 0, R = (r - l) / 2 + 1;
        while (R - L > 1){
            int M = (L + R) / 2;
            auto tmp = S.prod(l, l + M);
            if (l + M + tmp <= r) L = M;
            else R = M;
        }
        cout << L << "\n";
    }
}

提出情報

提出日時
問題 G - Simultaneous Kagamimochi 2
ユーザ potato167
言語 C++ 17 (gcc 12.2)
得点 575
コード長 1708 Byte
結果 AC
実行時間 140 ms
メモリ 19548 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 575 / 575
結果
AC × 2
AC × 46
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 02_handmade_40.txt, 02_handmade_41.txt, 02_handmade_42.txt, 02_handmade_43.txt, 02_handmade_44.txt, 02_handmade_45.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3456 KiB
00_sample_01.txt AC 1 ms 3424 KiB
01_random_02.txt AC 125 ms 19456 KiB
01_random_03.txt AC 124 ms 19456 KiB
01_random_04.txt AC 124 ms 19488 KiB
01_random_05.txt AC 124 ms 19368 KiB
01_random_06.txt AC 123 ms 19412 KiB
01_random_07.txt AC 119 ms 14144 KiB
01_random_08.txt AC 51 ms 3812 KiB
01_random_09.txt AC 131 ms 18356 KiB
01_random_10.txt AC 126 ms 19408 KiB
01_random_11.txt AC 134 ms 19368 KiB
01_random_12.txt AC 139 ms 19392 KiB
01_random_13.txt AC 127 ms 19424 KiB
01_random_14.txt AC 136 ms 19436 KiB
01_random_15.txt AC 129 ms 19360 KiB
01_random_16.txt AC 139 ms 19420 KiB
01_random_17.txt AC 126 ms 19412 KiB
01_random_18.txt AC 124 ms 19360 KiB
01_random_19.txt AC 125 ms 19444 KiB
01_random_20.txt AC 125 ms 19396 KiB
01_random_21.txt AC 118 ms 19316 KiB
01_random_22.txt AC 131 ms 19320 KiB
01_random_23.txt AC 132 ms 19384 KiB
01_random_24.txt AC 132 ms 19384 KiB
01_random_25.txt AC 132 ms 19412 KiB
01_random_26.txt AC 131 ms 19460 KiB
01_random_27.txt AC 126 ms 19384 KiB
01_random_28.txt AC 127 ms 19444 KiB
01_random_29.txt AC 127 ms 19476 KiB
01_random_30.txt AC 127 ms 19400 KiB
01_random_31.txt AC 126 ms 19548 KiB
01_random_32.txt AC 102 ms 10192 KiB
01_random_33.txt AC 59 ms 4600 KiB
01_random_34.txt AC 46 ms 3572 KiB
01_random_35.txt AC 70 ms 19408 KiB
01_random_36.txt AC 71 ms 19428 KiB
01_random_37.txt AC 69 ms 19408 KiB
01_random_38.txt AC 70 ms 19404 KiB
01_random_39.txt AC 71 ms 19444 KiB
02_handmade_40.txt AC 22 ms 3496 KiB
02_handmade_41.txt AC 21 ms 3452 KiB
02_handmade_42.txt AC 24 ms 3452 KiB
02_handmade_43.txt AC 122 ms 19376 KiB
02_handmade_44.txt AC 140 ms 19372 KiB
02_handmade_45.txt AC 140 ms 19364 KiB