結果

問題 No.1093 区間の和 / Sum of Range
ユーザー onsen_manjuuuonsen_manjuuu
提出日時 2020-06-24 02:48:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 858 bytes
コンパイル時間 1,720 ms
コンパイル使用メモリ 176,212 KB
実行使用メモリ 8,692 KB
最終ジャッジ日時 2023-09-16 20:37:15
合計ジャッジ時間 8,006 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 132 ms
7,320 KB
testcase_02 AC 58 ms
4,900 KB
testcase_03 AC 56 ms
7,616 KB
testcase_04 AC 37 ms
5,344 KB
testcase_05 AC 198 ms
8,692 KB
testcase_06 AC 38 ms
4,624 KB
testcase_07 AC 103 ms
6,144 KB
testcase_08 AC 98 ms
7,556 KB
testcase_09 AC 173 ms
7,356 KB
testcase_10 AC 101 ms
7,156 KB
testcase_11 AC 138 ms
5,112 KB
testcase_12 AC 100 ms
6,768 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 154 ms
4,984 KB
testcase_15 AC 41 ms
4,660 KB
testcase_16 AC 185 ms
5,984 KB
testcase_17 AC 141 ms
4,376 KB
testcase_18 AC 97 ms
4,544 KB
testcase_19 AC 11 ms
4,376 KB
testcase_20 AC 82 ms
4,540 KB
testcase_21 AC 178 ms
5,132 KB
testcase_22 AC 181 ms
7,228 KB
testcase_23 AC 125 ms
4,424 KB
testcase_24 AC 40 ms
4,620 KB
testcase_25 AC 156 ms
4,692 KB
testcase_26 AC 133 ms
7,468 KB
testcase_27 AC 166 ms
5,444 KB
testcase_28 AC 119 ms
7,076 KB
testcase_29 AC 194 ms
4,428 KB
testcase_30 AC 28 ms
4,380 KB
testcase_31 AC 47 ms
5,408 KB
testcase_32 AC 65 ms
4,976 KB
testcase_33 AC 190 ms
6,824 KB
testcase_34 AC 13 ms
4,380 KB
testcase_35 AC 191 ms
4,868 KB
testcase_36 AC 176 ms
7,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = long long;


int main()
{
    int n, k, q; cin >> n >> k;
    vector<int> sum(n + 1), que, s;
    for(int i = 1; i <= n; i++) {
        int a; cin >> a;
        sum[i] = sum[i - 1] + a;
    }
    cin >> q; que.resize(q);
    for(int i = 0; i < n - k + 1; i++) s.emplace_back(sum[i + k] - sum[i]);
    for(int i = 0; i < q; i++)cin >> que[i];


    vector<int> ar;
    { //座圧
        map<int,int> mp;
        int cur = 0;
        for(auto i : s)mp[i] = -1;
        for(auto i : que)mp[i] = -1;
        for(auto &i: mp)i.second = cur++;
        for(auto &i: que)i = mp[i];
        ar.resize(cur + 2);
        for(auto i : s)ar[mp[i]]++;
        cerr << cur << endl;
        for(int i = 1; i < cur + 2; i++)ar[i] += ar[i - 1];
    }



    for(auto i : que) {
        cout << ar[i] << endl;
    }


}
0