結果
問題 | No.896 友達以上恋人未満 |
ユーザー |
![]() |
提出日時 | 2019-09-27 22:10:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 698 ms / 3,500 ms |
コード長 | 1,916 bytes |
コンパイル時間 | 1,664 ms |
コンパイル使用メモリ | 175,856 KB |
実行使用メモリ | 144,304 KB |
最終ジャッジ日時 | 2024-09-24 16:01:57 |
合計ジャッジ時間 | 4,164 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
ソースコード
#include <bits/stdc++.h>using namespace std;using lint = long long;template<class T = int> using V = vector<T>;template<class T = int> using VV = V< V<T> >;V<> sieve(int n) {V<bool> b((n + 1) / 3, true);V<> res{2, 3};for (int p = 5, d = 2; p * p < n; p += d, d = 6 - d) if (b[p / 3]) {for (int i = 5 * p, d = 2 * p; i < n; i += d, d = 6 * p - d) b[i / 3] = false;}for (int p = 5, d = 2; p < n; p += d, d = 6 - d) if(b[p / 3]) res.push_back(p);while (!res.empty() and res.back() >= n) res.pop_back();return res;}template<class T> void fmult(V<T>& a, const V<>& ps) {int n = a.size();for (int p : ps) {for (int i = (n - 1) / p; i; --i) {a[i] += a[i * p];}}}int main() {cin.tie(nullptr); ios::sync_with_stdio(false);int m, n; cin >> m >> n;lint mulX, addX, mulY, addY, MOD; cin >> mulX >> addX >> mulY >> addY >> MOD;V<> 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];V<lint> z(MOD);for (int i = 0; i < m; ++i) {z[x[i]] += y[i];}int nx = x.back(), ny = y.back();for (int i = m; i < n; ++i) {nx = nx * mulX + addX & MOD - 1;ny = ny * mulY + addY & MOD - 1;z[nx] += ny;}fmult(z, sieve(MOD));lint acc = 0;for (int i = 0; i < m; ++i) {lint res = 0;if (a[i] < MOD) {res += z[a[i]];}if ((lint)a[i] * b[i] < MOD) {res -= z[a[i] * b[i]];}cout << res << '\n';acc ^= res;}int na = a.back(), nb = b.back();for (int i = m; i < n; ++i) {na = (na * mulX + addX - 1 & MOD - 1) + 1;nb = (nb * mulY + addY - 1 & MOD - 1) + 1;lint res = 0;if (na < MOD) {res += z[na];}if ((lint)na * nb < MOD) {res -= z[na * nb];}acc ^= res;}cout << acc << '\n';}