結果

問題 No.2359 A in S ?
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-07-09 07:46:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 515 ms / 2,000 ms
コード長 1,234 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 204,232 KB
実行使用メモリ 252,540 KB
最終ジャッジ日時 2023-09-30 10:18:38
合計ジャッジ時間 14,718 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 236 ms
252,392 KB
testcase_01 AC 239 ms
252,540 KB
testcase_02 AC 238 ms
252,220 KB
testcase_03 AC 238 ms
252,292 KB
testcase_04 AC 474 ms
252,168 KB
testcase_05 AC 510 ms
252,344 KB
testcase_06 AC 475 ms
252,248 KB
testcase_07 AC 515 ms
252,348 KB
testcase_08 AC 493 ms
252,300 KB
testcase_09 AC 469 ms
252,292 KB
testcase_10 AC 482 ms
252,412 KB
testcase_11 AC 494 ms
252,228 KB
testcase_12 AC 475 ms
252,224 KB
testcase_13 AC 471 ms
252,352 KB
testcase_14 AC 477 ms
252,484 KB
testcase_15 AC 469 ms
252,288 KB
testcase_16 AC 474 ms
252,384 KB
testcase_17 AC 477 ms
252,288 KB
testcase_18 AC 481 ms
252,244 KB
testcase_19 AC 479 ms
252,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template<typename T>
T ceil(T a, T b){
    assert(b != 0);
    if (a == 0) return 0;

    if (a > 0 && b > 0) return (a+b-1) / b;
    else if (a < 0 && b < 0) return (a+b+1) / b;
    else return a / b;
}

template<typename T>
T floor(T a, T b){
    assert(b != 0);
    if (a == 0) return 0;

    if (a > 0 && b < 0) return (a-b-1) / b;
    else if (a < 0 && b > 0) return (a-b+1) / b;
    else return a / b;
}


int main(){

    ll N, M, L, R, X, Y, A, l, r;
    const ll K = 316;
    cin >> N >> M;

    vector<ll> ans(1e5+1);
    vector<vector<ll>> cnt(K, vector<ll>(1e5+1));

    for (int i=0; i<N; i++){
        cin >> L >> R >> X >> Y;
        l = ceil(L-Y, X);
        r = floor(R-Y, X);

        if (X >= K){
            for (int i=l; i<=r; i++) ans[X*i+Y]++;
        }
        else{
            cnt[X][X*l+Y]++;
            if (X*r+Y+X<=1e5) cnt[X][X*r+Y+X]--;
        }
    }

    for (int i=0; i<K; i++){
        for (int j=i; j<=1e5; j++) cnt[i][j] += cnt[i][j-i];
        for (int j=0; j<=1e5; j++){
            ans[j] += cnt[i][j];
        }
    }

    for (int i=0; i<M; i++){
        cin >> A;
        cout << ans[A] << endl;
    }

    return 0;
}
0