結果

問題 No.1093 区間の和 / Sum of Range
ユーザー tktk_snsn
提出日時 2021-03-30 22:14:22
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 1,143 bytes
コンパイル時間 899 ms
コンパイル使用メモリ 77,456 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-30 22:47:38
合計ジャッジ時間 5,237 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

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