結果
| 問題 |
No.896 友達以上恋人未満
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2019-09-27 22:07:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,913 bytes |
| コンパイル時間 | 1,836 ms |
| コンパイル使用メモリ | 177,040 KB |
| 実行使用メモリ | 212,428 KB |
| 最終ジャッジ日時 | 2024-09-24 14:51:37 |
| 合計ジャッジ時間 | 4,531 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 6 MLE * 1 |
ソースコード
#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(n), y(n), 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];
for (int i = m; i < n; ++i) {
x[i] = x[i - 1] * mulX + addX & MOD - 1;
y[i] = y[i - 1] * mulY + addY & MOD - 1;
}
V<lint> z(MOD);
for (int i = 0; i < n; ++i) {
z[x[i]] += y[i];
}
V<>().swap(x);
V<>().swap(y);
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';
}
risujiroh