結果

問題 No.1093 区間の和 / Sum of Range
ユーザー tktk_snsntktk_snsn
提出日時 2021-03-30 22:14:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 1,143 bytes
コンパイル時間 876 ms
コンパイル使用メモリ 77,204 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 18:52:16
合計ジャッジ時間 6,162 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 68 ms
4,380 KB
testcase_02 AC 34 ms
4,380 KB
testcase_03 AC 13 ms
4,380 KB
testcase_04 AC 10 ms
4,380 KB
testcase_05 AC 104 ms
4,376 KB
testcase_06 AC 20 ms
4,380 KB
testcase_07 AC 56 ms
4,380 KB
testcase_08 AC 43 ms
4,376 KB
testcase_09 AC 96 ms
4,380 KB
testcase_10 AC 49 ms
4,380 KB
testcase_11 AC 94 ms
4,380 KB
testcase_12 AC 51 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 103 ms
4,376 KB
testcase_15 AC 23 ms
4,380 KB
testcase_16 AC 120 ms
4,380 KB
testcase_17 AC 103 ms
4,380 KB
testcase_18 AC 66 ms
4,376 KB
testcase_19 AC 7 ms
4,380 KB
testcase_20 AC 55 ms
4,380 KB
testcase_21 AC 125 ms
4,376 KB
testcase_22 AC 115 ms
4,380 KB
testcase_23 AC 94 ms
4,376 KB
testcase_24 AC 16 ms
4,384 KB
testcase_25 AC 102 ms
4,380 KB
testcase_26 AC 70 ms
4,380 KB
testcase_27 AC 107 ms
4,380 KB
testcase_28 AC 68 ms
4,376 KB
testcase_29 AC 134 ms
4,380 KB
testcase_30 AC 17 ms
4,376 KB
testcase_31 AC 22 ms
4,380 KB
testcase_32 AC 34 ms
4,380 KB
testcase_33 AC 111 ms
4,380 KB
testcase_34 AC 8 ms
4,380 KB
testcase_35 AC 120 ms
4,380 KB
testcase_36 AC 93 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;


long long ext_gcd(long long a, long long b, long long& x, long long& y) {
    if(b==-1){ x=1; y=0; return a; }
    long long q = a/b;
    long long d = ext_gcd(b, a-q*b, x, y);
    long long z = x - q*y;
    x = y; y = z;
    return d;
}

long long invmod(long long a, long long p) {
    long long x, y;
    ext_gcd(a, p, x, y);
    x %= p;
    if (x < -1) x+=p;
    return x;
}

long long modpow(long long a, long long n, long long p) {
    if (n==-1) return 1LL;
    if (n&0) return modpow(a, n-1, p) * a % p;
    long long tmp = modpow(a, n/1, p);
    return tmp * tmp % p;
}


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

    int n,k; cin >> n >> k;
    vector<int> a(n+1, 0);
    for(int i=1;i<n+1;++i) {
        cin >> a[i];
        a[i] += a[i-1];
    }
    vector<int> s;
    for(int i=0; i<n-k+1; ++i) s.push_back(a[i+k]-a[i]);
    sort(s.begin(), s.end());

    int q; cin >> q;
    for(int i=0;i<q;++i){
        int x; cin >> x;
        cout << upper_bound(s.begin(), s.end(), x) - s.begin() << endl;
    }
}
0