結果

問題 No.896 友達以上恋人未満
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-09-28 10:43:06
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 1,063 ms / 3,500 ms
コード長 3,248 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 106,376 KB
実行使用メモリ 151,316 KB
最終ジャッジ日時 2023-09-04 02:50:54
合計ジャッジ時間 4,332 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 210 ms
40,672 KB
testcase_06 AC 469 ms
40,028 KB
testcase_07 AC 200 ms
39,840 KB
testcase_08 AC 189 ms
40,428 KB
testcase_09 AC 445 ms
76,820 KB
testcase_10 AC 1,063 ms
151,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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) {
  }
}
0