結果

問題 No.2324 Two Countries within UEC
ユーザー kobaryo222kobaryo222
提出日時 2023-05-28 13:58:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,226 bytes
コンパイル時間 1,886 ms
コンパイル使用メモリ 199,092 KB
実行使用メモリ 4,932 KB
最終ジャッジ日時 2023-08-27 08:46:50
合計ジャッジ時間 8,658 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 静的メンバ関数 ‘static int ArbitraryModInt::set_mod(int)’ 内:
main.cpp:32:46: 警告: 非 void を戻す関数内に return 文がありません [-Wreturn-type]
   32 |     static int set_mod(int md) { mod() = md; }
      |                                              ^

ソースコード

diff #

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

using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF (1LL << 60)
#define all(v) (v).begin(), (v).end()

template <class T>
void chmin(T &a, T b) {
    if (a > b) a = b;
}

template <class T>
void chmax(T &a, T b) {
    if (a < b) a = b;
}

struct ArbitraryModInt {
    int x;

    ArbitraryModInt() : x(0) {}

    ArbitraryModInt(int64_t y)
        : x(y >= 0 ? y % mod() : (mod() - (-y) % mod()) % mod()) {}

    static int &mod() {
        static int mod = 0;
        return mod;
    }

    static int set_mod(int md) { mod() = md; }

    ArbitraryModInt &operator+=(const ArbitraryModInt &p) {
        if ((x += p.x) >= mod()) x -= mod();
        return *this;
    }

    ArbitraryModInt &operator-=(const ArbitraryModInt &p) {
        if ((x += mod() - p.x) >= mod()) x -= mod();
        return *this;
    }

    ArbitraryModInt &operator*=(const ArbitraryModInt &p) {
        unsigned long long a = (unsigned long long)x * p.x;
        unsigned xh = (unsigned)(a >> 32), xl = (unsigned)a, d, m;
        asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(mod()));
        x = m;
        return *this;
    }

    ArbitraryModInt &operator/=(const ArbitraryModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ArbitraryModInt operator-() const { return ArbitraryModInt(-x); }

    ArbitraryModInt operator+(const ArbitraryModInt &p) const {
        return ArbitraryModInt(*this) += p;
    }

    ArbitraryModInt operator-(const ArbitraryModInt &p) const {
        return ArbitraryModInt(*this) -= p;
    }

    ArbitraryModInt operator*(const ArbitraryModInt &p) const {
        return ArbitraryModInt(*this) *= p;
    }

    ArbitraryModInt operator/(const ArbitraryModInt &p) const {
        return ArbitraryModInt(*this) /= p;
    }

    bool operator==(const ArbitraryModInt &p) const { return x == p.x; }

    bool operator!=(const ArbitraryModInt &p) const { return x != p.x; }

    ArbitraryModInt inverse() const {
        int a = x, b = mod(), u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ArbitraryModInt(u);
    }

    ArbitraryModInt pow(int64_t n) const {
        ArbitraryModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ArbitraryModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ArbitraryModInt &a) {
        int64_t t;
        is >> t;
        a = ArbitraryModInt(t);
        return (is);
    }
};

int main() {
    ll N, M, P, Q;
    cin >> N >> M >> P >> Q;
    vector<ll> x(Q), f(Q);
    ArbitraryModInt::set_mod(P);

    rep(i, Q) {
        cin >> x[i] >> f[i];
        ArbitraryModInt t =
            ArbitraryModInt(f[i]) * ArbitraryModInt(x[i]).inverse();
        ll ans = 0;
        ll tx = t.x;
        if (tx == 0) tx = P;
        // cout << tx << endl;
        if (M >= tx) {
            ans++;
            ans += (M - tx) / P;
        }
        cout << ans << endl;
    }
}
0