結果

問題 No.2359 A in S ?
ユーザー milanis48663220milanis48663220
提出日時 2023-06-23 23:38:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 911 ms / 2,000 ms
コード長 2,611 bytes
コンパイル時間 1,083 ms
コンパイル使用メモリ 118,984 KB
実行使用メモリ 202,744 KB
最終ジャッジ日時 2023-09-13 18:48:11
合計ジャッジ時間 14,216 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
200,396 KB
testcase_01 AC 72 ms
200,456 KB
testcase_02 AC 78 ms
201,016 KB
testcase_03 AC 73 ms
200,784 KB
testcase_04 AC 905 ms
202,268 KB
testcase_05 AC 903 ms
202,684 KB
testcase_06 AC 905 ms
202,516 KB
testcase_07 AC 277 ms
202,272 KB
testcase_08 AC 310 ms
202,404 KB
testcase_09 AC 307 ms
202,412 KB
testcase_10 AC 309 ms
202,716 KB
testcase_11 AC 314 ms
202,744 KB
testcase_12 AC 907 ms
202,480 KB
testcase_13 AC 907 ms
202,404 KB
testcase_14 AC 906 ms
202,392 KB
testcase_15 AC 308 ms
202,460 KB
testcase_16 AC 905 ms
202,460 KB
testcase_17 AC 905 ms
202,464 KB
testcase_18 AC 903 ms
202,520 KB
testcase_19 AC 911 ms
202,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

const int N = 100000;
const int M = 500;

int ans[N+1];
int sum[M+1][N+1000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m; cin >> n >> m;
    vector<int> l(n), r(n), x(n), y(n);
    for(int i = 0; i < n; i++){
        cin >> l[i] >> r[i] >> x[i] >> y[i];

    }
    vector<int> a(m);
    for(int i = 0; i < m; i++){
        cin >> a[i];
    }
    
    for(int i = 0; i < n; i++){
        if(x[i] >= M){
            for(int p = 0; p*x[i]+y[i] <= r[i]; p++){
                int s = p*x[i]+y[i];
                if(s >= l[i]){
                    ans[s]++;
                }
            }
        }else{
            if(l[i]%x[i] <= y[i]){
                l[i] = (l[i]/x[i])*x[i]+y[i];
            }else{
                l[i] = (l[i]/x[i]+1)*x[i]+y[i];
            }

            if(r[i]%x[i] < y[i]){
                r[i] = (r[i]/x[i]-1)*x[i]+y[i];
            }else{
                r[i] = (r[i]/x[i])*x[i]+y[i];
            }
            chmax(l[i], y[i]);
            if(l[i] > r[i]) continue;
            sum[x[i]][l[i]]++;
            sum[x[i]][r[i]+x[i]]--;
        }
    }
    for(int d = 1; d <= M; d++){
        for(int x = d; x <= N; x++){
            sum[d][x] += sum[d][x-d];
        }
    }
    for(int aa: a){
        int out = ans[aa];
        for(int x = 1; x <= M; x++){
            out += sum[x][aa];
        }
        cout << out << endl;
    }
}
0