結果

問題 No.896 友達以上恋人未満
ユーザー mkawa2mkawa2
提出日時 2022-03-24 12:22:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,577 ms / 3,500 ms
コード長 1,724 bytes
コンパイル時間 2,284 ms
コンパイル使用メモリ 200,692 KB
実行使用メモリ 134,320 KB
最終ジャッジ日時 2024-04-20 21:46:05
合計ジャッジ時間 8,040 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 399 ms
36,132 KB
testcase_06 AC 687 ms
35,968 KB
testcase_07 AC 420 ms
36,096 KB
testcase_08 AC 413 ms
35,968 KB
testcase_09 AC 1,092 ms
68,824 KB
testcase_10 AC 2,577 ms
134,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #include <atcoder/all>
// using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define popcnt(x) __builtin_popcount(x)
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
const int inf = 1e9;
const ll lim = 1e18;
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int m, n, mulx, addx, muly, addy, mod;
  cin >> m >> n >> mulx >> addx >> muly >> addy >> mod;
  vi xx(m), yy(m), aa(m), bb(m);
  rep(i, m) cin >> xx[i];
  rep(i, m) cin >> yy[i];
  rep(i, m) cin >> aa[i];
  rep(i, m) cin >> bb[i];

  int mask = mod - 1;
  vll zz(mod, 0LL);
  rep(i, m) zz[xx[i]] += yy[i];
  ll x = xx[m - 1], y = yy[m - 1];
  rep(i, n - m) {
    x = (x * mulx + addx) & mask;
    y = (y * muly + addy) & mask;
    zz[x] += y;
  }

  rep(i, mod) {
    if (i == 0) continue;
    for (int j = i + i; j < mod; j += i) zz[i] += zz[j];
  }

  // rep(i,mod) cout<<zz[i]<<endl;

  ll s = 0;
  rep(i, m) {
    ll ans;
    if (aa[i] == mod)
      ans = 0;
    else if ((ll)aa[i] * bb[i] < mod)
      ans = zz[aa[i]] - zz[aa[i] * bb[i]];
    else
      ans = zz[aa[i]];
    s ^= ans;
    cout << ans << endl;
  }

  int a = aa[m - 1], b = bb[m - 1];
  rep(_, n - m) {
    a = ((a * mulx + addx + mod - 1) & mask) + 1;
    b = ((b * muly + addy + mod - 1) & mask) + 1;
    if (a == mod) continue;
    if ((ll)a * b < mod)
      s ^= zz[a] - zz[a * b];
    else
      s ^= zz[a];
  }
  cout << s << endl;

  return 0;
}
0