結果

問題 No.2359 A in S ?
ユーザー hari64hari64
提出日時 2023-06-23 22:56:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 427 ms / 2,000 ms
コード長 5,091 bytes
コンパイル時間 4,735 ms
コンパイル使用メモリ 217,944 KB
実行使用メモリ 5,688 KB
最終ジャッジ日時 2023-09-13 18:04:10
合計ジャッジ時間 9,145 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,428 KB
testcase_02 AC 4 ms
4,556 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 292 ms
4,376 KB
testcase_05 AC 310 ms
4,428 KB
testcase_06 AC 293 ms
4,428 KB
testcase_07 AC 284 ms
4,376 KB
testcase_08 AC 427 ms
5,688 KB
testcase_09 AC 282 ms
4,376 KB
testcase_10 AC 295 ms
4,428 KB
testcase_11 AC 300 ms
4,444 KB
testcase_12 AC 284 ms
4,568 KB
testcase_13 AC 291 ms
4,440 KB
testcase_14 AC 288 ms
4,432 KB
testcase_15 AC 280 ms
4,424 KB
testcase_16 AC 312 ms
4,444 KB
testcase_17 AC 300 ms
4,444 KB
testcase_18 AC 292 ms
4,376 KB
testcase_19 AC 296 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef __int128_t lll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef tuple<ll, ll, ll> tt;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef vector<pl> vp;
typedef vector<tt> vt;
typedef vector<string> vs;

const ll INF = 1000000010;
const ll INFL = INF * INF;
const double MYPI = acos(-1);
const ld epsilon = 1e-10;

#define ovl(a, b, c, d, e, ...) e
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define DEBUG(...) DEBUG_(#__VA_ARGS__, __VA_ARGS__)
#define REP1(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, l, r) for (int i = (l); i < (r); i++)
#define REP3(i, l, r, d) for (int i = (l); i < (r); i += (d))
#define REP(...) ovl(__VA_ARGS__, REP3, REP2, REP1)(__VA_ARGS__)
#define RREP1(i, n) for (int i = (n)-1; i >= 0; i--)
#define RREP2(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define RREP3(i, l, r, d) for (int i = (r)-1; i >= (l); i -= (d))
#define RREP(...) ovl(__VA_ARGS__, RREP3, RREP2, RREP1)(__VA_ARGS__)
#define EACH1(e, a) for (auto &e : a)
#define EACH2(x, y, a) for (auto &[x, y] : a)
#define EACH3(x, y, z, a) for (auto &[x, y, z] : a)
#define EACH(...) ovl(__VA_ARGS__, EACH3, EACH2, EACH1)(__VA_ARGS__)
#define ALL(x) begin(x), end(x)
#define RALL(x) (x).rbegin(), (x).rend()
#define sz(x) (ll) x.size()
#define LB(a, x) (lower_bound(ALL(a), x) - a.begin())
#define UB(a, x) (upper_bound(ALL(a), x) - a.begin())
#define FLG(x, i) (((x) >> (i)) & 1)
#define CNTBIT(x) __builtin_popcountll(x)
#define TOPBIT(t) (t == 0 ? -1 : 63 - __builtin_clzll(t))
#define IN(x, a, b) ((a) <= (x) && (x) < (b))
#define int ll

template <class T, class... Ts>
void OUT(const T &a, const Ts &...b) {
    cout << a;
    (cout << ... << (cout << " ", b));
    cout << endl;
}

template <class T>
void DEBUG_(string_view name, const T &a) {
    cout << name << ": " << a << endl;
}

template <class T>
void DEBUG_(string_view name, const vector<T> &a) {
    cout << name << ": ";
    REP(i, sz(a)) cout << a[i] << " ";
    cout << endl;
}

template <class T, class U>
bool chmax(T &x, const U &y) {
    return x < y ? x = y, 1 : 0;
}
template <class T, class U>
bool chmin(T &x, const U &y) {
    return x > y ? x = y, 1 : 0;
}

template <class T>
using minheap = priority_queue<T, vector<T>, greater<T>>;

template <class T>
using maxheap = priority_queue<T>;

const vl dy = {1, 0, -1, 0, 1, -1, -1, 1};
const vl dx = {0, 1, 0, -1, 1, 1, -1, -1};

template <class T = ll>
struct Edge {
    ll from, to;
    T cost;
    ll idx;
    Edge(ll f, ll t, T c = 1, ll i = -1) : from(f), to(t), cost(c), idx(i) {}
    operator int() const { return to; }
};

template <class T = ll>
struct Graph {
    vector<vector<Edge<T>>> g;
    ll es;
    explicit Graph(ll n) : g(n), es(0) {}
    size_t size() const { return sz(g); }
    void add_directed_edge(ll from, ll to, T cost = 1) {
        g[from].eb(from, to, cost, es++);
    }
    void add_edge(ll from, ll to, T cost = 1) {
        g[from].eb(from, to, cost, es);
        g[to].eb(to, from, cost, es++);
    }
    inline vector<Edge<T>> &operator[](const int &k) { return g[k]; }
    inline const vector<Edge<T>> &operator[](const int &k) const {
        return g[k];
    }
};

//-----------------------------------------------------------------------

void solve() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    int N, M;
    cin >> N >> M;

    vector<vector<map<int, int>>> small(100 + 1,
                                        vector<map<int, int>>(100 + 1));
    vector<int> large(100000 + 1);

    REP(i, N) {
        int L, R, X, Y;
        cin >> L >> R >> X >> Y;
        if (X <= 100) {
            small[X][Y][L - 1]++;
            small[X][Y][R]--;
        } else {
            while (Y <= 100000) {
                if (IN(Y, L, R + 1)) {
                    large[Y]++;
                }
                Y += X;
            }
        }
    }
    REP(X, 1, 100 + 1) {
        REP(Y, 0, 100 + 1) {
            if (small[X][Y].empty()) continue;
            map<int, int> nmap;
            int now = 0;
            EACH(key, val, small[X][Y]) {
                now += val;
                nmap[key] = now;
            }
            nmap[-INF] = 0;
            nmap[INF] = 0;
            small[X][Y] = nmap;
        }
    }

    REP(i, M) {
        int A;
        cin >> A;
        int cnt = 0;
        REP(x, 1, 100 + 1) {
            int y = A % x;
            if (small[x][y].empty()) continue;
            // DEBUG(y);
            // DEBUG(x);
            // DEBUG(get<0>(*--small[x][y].lower_bound(A)));
            // DEBUG(get<1>(*--small[x][y].lower_bound(A)));
            cnt += get<1>(*--small[x][y].lower_bound(A));
        }
        OUT(large[A] + cnt);
    }
}

signed main() {
    solve();

    return 0;
}
0