結果

問題 No.1093 区間の和 / Sum of Range
ユーザー WarToksWarToks
提出日時 2020-07-04 22:15:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,750 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 52,792 KB
実行使用メモリ 4,404 KB
最終ジャッジ日時 2023-10-19 17:21:12
合計ジャッジ時間 3,001 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 7 ms
4,348 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 8 ms
4,348 KB
testcase_04 AC 5 ms
4,348 KB
testcase_05 AC 8 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 6 ms
4,348 KB
testcase_08 AC 8 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 8 ms
4,348 KB
testcase_11 AC 7 ms
4,348 KB
testcase_12 AC 10 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 8 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 11 ms
4,348 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 6 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 6 ms
4,348 KB
testcase_21 AC 11 ms
4,348 KB
testcase_22 AC 13 ms
4,348 KB
testcase_23 AC 7 ms
4,348 KB
testcase_24 AC 4 ms
4,348 KB
testcase_25 AC 5 ms
4,348 KB
testcase_26 AC 12 ms
4,348 KB
testcase_27 AC 8 ms
4,348 KB
testcase_28 AC 10 ms
4,348 KB
testcase_29 AC 11 ms
4,404 KB
testcase_30 AC 3 ms
4,348 KB
testcase_31 AC 6 ms
4,348 KB
testcase_32 AC 5 ms
4,348 KB
testcase_33 AC 12 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 7 ms
4,348 KB
testcase_36 AC 13 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx")

#include <stdio.h>
#include <algorithm>

static constexpr int buffer_size = 1 << 17;
static char buffer[buffer_size];
static int pos = buffer_size;

inline char get_char(void){
    if(pos == buffer_size){ fread_unlocked(buffer, 1, buffer_size, stdin); pos = 0; }
    return buffer[pos++];
}

inline int getint(void){
    int res = 0; char c = get_char();
    if(c == '-'){
        while((c = get_char() - '0') >= 0) res = 10 * res + c;
        return -res;
    }
    res = c - '0';
    while((c = get_char() - '0') >= 0) res = 10 * res + c;
    return res;
}

inline void put_char(const char c){
    if(pos == buffer_size){ fwrite_unlocked(buffer, 1, buffer_size, stdout); pos = 0; }
    buffer[pos++] = c;
}


char buffer2[20];
inline void println(int x){
    if(x){
        int idx = 0; do{ buffer2[idx++] = x % 10; x /= 10; } while(x);
        while(idx) put_char( buffer2[--idx] + '0');
    }
    else put_char('0');
    put_char('\n');
}


constexpr int MAX_N = 100000;
constexpr int MAX_Q = 100000;
int A[MAX_N], S[MAX_N], X[MAX_N];


int main(void){
    const int n = getint(), k = getint();
    for(int i = 0; i < n; ++i) A[i] = getint();{
        int val = 0; for(int i = 0; i < k; ++i) val += A[i];
        for(int i = 0, j = k; j < n; ++i, ++j){
            S[i] = val;
            val += A[j] - A[i];
        }
        S[n - k] = val;
    }
    int* T = S + n - k + 1;
    std::sort(S, T);

    const int q = getint();
    for(int i = 0; i < q; ++i) X[i] = getint();
    
    pos = 0;
    for(int i = 0; i < q; ++i){
        const int res = std::upper_bound(S, T, X[i]) - S;
        println(res);
    }
    
    fwrite_unlocked(buffer, 1, pos, stdout);
    return 0;
}
0