結果

問題 No.896 友達以上恋人未満
ユーザー vwxyzvwxyz
提出日時 2024-04-15 13:34:47
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,868 ms / 3,500 ms
コード長 1,659 bytes
コンパイル時間 1,033 ms
コンパイル使用メモリ 91,868 KB
実行使用メモリ 136,416 KB
最終ジャッジ日時 2024-04-15 13:34:56
合計ジャッジ時間 7,883 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 674 ms
36,420 KB
testcase_06 AC 1,868 ms
36,496 KB
testcase_07 AC 668 ms
36,556 KB
testcase_08 AC 618 ms
36,492 KB
testcase_09 AC 947 ms
69,760 KB
testcase_10 AC 1,557 ms
136,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
#define int long long

signed main() {
    int M, N, mulX, addX, mulY, addY, mod;
    cin >> M >> N >> mulX >> addX >> mulY >> addY >> mod;

    vector<int> X(M), Y(M), A(M), B(M);
    for (int i = 0; i < M; ++i)
        cin >> X[i];
    for (int i = 0; i < M; ++i)
        cin >> Y[i];
    for (int i = 0; i < M; ++i)
        cin >> A[i];
    for (int i = 0; i < M; ++i)
        cin >> B[i];
    vector<int> cnt(mod, 0);
    for (int i = 0; i < M; ++i)
        cnt[X[i]] += Y[i];

    int x = X.back(), y = Y.back();
    for (int i = M; i < N; ++i) {
        x = (1LL * x * mulX + addX) % mod;
        y = (1LL * y * mulY + addY) % mod;
        cnt[x] += y;
    }

    vector<bool> is_prime(mod, true);
    for (int p = 2; p < mod; ++p) {
        if (is_prime[p]) {
            for (int x = (mod - 1) / p; x > 0; --x)
                cnt[x] += cnt[x * p];
            for (int i = 2 * p; i < mod; i += p)
                is_prime[i] = false;
        }
    }

    int ans = 0;
    for (int i = 0; i < M; ++i) {
        int a = A[i], b = B[i];
        int c = 0;
        if (a < mod)
            c += cnt[a];
        if (1LL * a * b < mod)
            c -= cnt[a * b];
        cout << c << endl;
        ans ^= c;
    }

    int a = A.back(), b = B.back();
    for (int i = M; i < N; ++i) {
        a = ((1LL * a * mulX + addX + mod - 1) % mod) + 1;
        b = ((1LL * b * mulY + addY + mod - 1) % mod) + 1;
        int c = 0;
        if (a < mod)
            c += cnt[a];
        if (1LL * a * b < mod)
            c -= cnt[a * b];
        ans ^= c;
    }

    cout << ans << endl;

    return 0;
}
0