結果
問題 | No.896 友達以上恋人未満 |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-09-28 10:43:06 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 1,244 ms / 3,500 ms |
コード長 | 3,248 bytes |
コンパイル時間 | 1,148 ms |
コンパイル使用メモリ | 120,612 KB |
実行使用メモリ | 151,164 KB |
最終ジャッジ日時 | 2024-06-22 02:38:16 |
合計ジャッジ時間 | 4,611 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 243 ms
41,272 KB |
testcase_06 | AC | 565 ms
40,952 KB |
testcase_07 | AC | 249 ms
39,660 KB |
testcase_08 | AC | 232 ms
39,524 KB |
testcase_09 | AC | 553 ms
77,068 KB |
testcase_10 | AC | 1,244 ms
151,164 KB |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } void main() { try { for (; ; ) { const M = readInt(); const N = readInt(); const MULX = readLong(); const ADDX = readLong(); const MULY = readLong(); const ADDY = readLong(); const MOD = readLong(); auto X = new long[M]; auto Y = new long[M]; auto A = new long[M]; auto B = new long[M]; foreach (i; 0 .. M) X[i] = readLong(); foreach (i; 0 .. M) Y[i] = readLong(); foreach (i; 0 .. M) A[i] = readLong(); foreach (i; 0 .. M) B[i] = readLong(); const len = cast(int)(MOD + 1); auto f = new long[len]; long x, y; foreach (i; 0 .. N) { if (i < M) { x = X[i]; y = Y[i]; } else { // x[i] = (x[i-1] * mulX + addX) % MOD // y[i] = (y[i-1] * mulY + addY) % MOD x = (x * MULX + ADDX) & (MOD - 1); y = (y * MULY + ADDY) & (MOD - 1); } debug { writefln("x = %s, y = %s", x, y); } f[cast(size_t)(x)] += y; } debug { writeln("f = ", f); } auto isnp = new bool[len]; foreach (p; 2 .. len) { if (!isnp[p]) { foreach_reverse (m; 1 .. (len - 1) / p + 1) { isnp[p * m] = true; f[m] += f[p * m]; } } } debug { writeln("f = ", f); } long ansSum; long a, b; foreach (i; 0 .. N) { if (i < M) { a = A[i]; b = B[i]; } else { // a[i] = (a[i-1] * mulX + addX + MOD - 1) % MOD + 1 // b[i] = (b[i-1] * mulY + addY + MOD - 1) % MOD + 1 a = ((a * MULX + ADDX + MOD - 1) & (MOD - 1)) + 1; b = ((b * MULY + ADDY + MOD - 1) & (MOD - 1)) + 1; } long ans = f[cast(size_t)(a)]; if (a * b < len) { ans -= f[cast(size_t)(a * b)]; } debug { writeln(a, " ", b, ": ", ans); } if (i < M) { writeln(ans); } ansSum ^= ans; } writeln(ansSum); } } catch (EOFException e) { } }