結果

問題 No.896 友達以上恋人未満
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-09-28 10:45:13
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 1,132 ms / 3,500 ms
コード長 3,255 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 108,408 KB
実行使用メモリ 150,400 KB
最終ジャッジ日時 2023-09-04 02:50:59
合計ジャッジ時間 4,386 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 207 ms
40,112 KB
testcase_06 AC 421 ms
40,452 KB
testcase_07 AC 184 ms
40,456 KB
testcase_08 AC 199 ms
40,120 KB
testcase_09 AC 422 ms
77,192 KB
testcase_10 AC 1,132 ms
150,400 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]) {
          for (int m = (len - 1) / p, n = m * p; m > 0; --m, n -= p) {
            isnp[n] = true;
            f[m] += f[n];
          }
        }
      }
      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