結果

問題 No.896 友達以上恋人未満
ユーザー finefine
提出日時 2019-09-27 23:16:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,613 ms / 3,500 ms
コード長 1,795 bytes
コンパイル時間 1,703 ms
コンパイル使用メモリ 168,612 KB
実行使用メモリ 82,060 KB
最終ジャッジ日時 2023-10-25 06:21:42
合計ジャッジ時間 7,150 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 433 ms
37,004 KB
testcase_06 AC 717 ms
36,996 KB
testcase_07 AC 431 ms
37,004 KB
testcase_08 AC 439 ms
37,004 KB
testcase_09 AC 1,058 ms
69,772 KB
testcase_10 AC 1,613 ms
82,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr int MAX_MOD = 1 << 24;
constexpr int MAXM = 1000;

ll z[MAX_MOD];
int a[MAXM], b[MAXM], x[MAXM], y[MAXM];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m, n;
    int mulx, addx, muly, addy;
    int mod;
    cin >> m >> n >> mulx >> addx >> muly >> addy >> mod;

    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];
    }

    for (int i = 0; i < m; i++) {
        z[x[i]] += y[i];
    }

    ll curx = x[m - 1], cury = y[m - 1], cura = a[m-1], curb = b[m-1];
    for (int i = m; i < n; i++) {
        curx = ((curx * mulx + addx) & (mod - 1));
        cury = ((cury * muly + addy) & (mod - 1));
        z[curx] += cury;
    }

    for (int aa = 1; aa <= mod; aa++) {
        for (int i = aa * 2; i < mod; i += aa) {
            z[aa] += z[i];
        }
    }

    ll all_ans = 0;
    for (int i = 0; i < m; i++) {
        ll ans = 0;
        if ((ll)a[i] * b[i] >= mod) {
            ans = (a[i] >= mod ? 0 : z[a[i]]);
        } else {
            ans = (a[i] >= mod ? 0 : z[a[i]] - z[a[i] * b[i]]);
        }
        cout << ans << "\n";
        all_ans ^= ans;
    }

    for (int i = m; i < n; i++) {
        cura = ((cura * mulx + addx + mod - 1) & (mod - 1)) + 1;
        curb = ((curb * muly + addy + mod - 1) & (mod - 1)) + 1;
        ll ans = 0;
        if (cura * curb >= mod) {
            ans = (cura >= mod ? 0 : z[cura]);
        } else {
            ans = (cura >= mod ? 0 : z[cura] - z[cura * curb]);
        }
        all_ans ^= ans;
    }

    cout << all_ans << "\n";
    return 0;
}
0