結果

問題 No.670 log は定数
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-01-25 00:05:31
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 3,211 ms / 4,000 ms
コード長 3,135 bytes
コンパイル時間 1,610 ms
コンパイル使用メモリ 110,948 KB
実行使用メモリ 24,108 KB
最終ジャッジ日時 2023-09-03 23:04:59
合計ジャッジ時間 36,838 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,056 ms
21,612 KB
testcase_01 AC 3,029 ms
20,860 KB
testcase_02 AC 3,029 ms
21,800 KB
testcase_03 AC 3,176 ms
21,928 KB
testcase_04 AC 3,127 ms
24,108 KB
testcase_05 AC 3,153 ms
21,564 KB
testcase_06 AC 3,137 ms
21,552 KB
testcase_07 AC 3,211 ms
23,328 KB
testcase_08 AC 3,083 ms
22,108 KB
testcase_09 AC 3,074 ms
22,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, 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(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


/********/
ulong seed;
int next() {
    seed = seed ^ (seed << 13);
    seed = seed ^ (seed >> 7);
    seed = seed ^ (seed << 17);
    return cast(int)(seed >> 33);
}
/********/

enum L = 10^^6;

int N, Q;
int[] A;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      Q = readInt();
      seed = readLong();
      foreach (i; 0 .. 10000) {
        next();
      }
      A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = next();
      }
      debug {
        writeln("A = ", A[0 .. min(10, $)]);
      }
      
      A.sort;
      auto xs = new int[L];
      auto js = new int[L];
      auto work = new int[L];
      auto buckets = new int[0x10001];
      auto ans = new int[L];
      long ansSum;
      for (int qL = 0; qL < Q; qL += L) {
        const qR = min(qL + L, Q);
        foreach (q; qL .. qR) {
          xs[q - qL] = next();
        }
        const len = qR - qL;
        debug {
          if (qL / L < 10) {
            writeln("queries ", xs[0 .. min(len, 10)]);
          }
        }
        foreach (j; 0 .. len) {
          js[j] = j;
        }
        
        // radix sort
        buckets[] = 0;
        foreach (j; 0 .. len) ++buckets[(xs[js[j]] & 0xffff) + 1];
        foreach (h; 0 .. 0x10000) buckets[h + 1] += buckets[h];
        foreach (j; 0 .. len) work[buckets[xs[js[j]] & 0xffff]++] = js[j];
        buckets[] = 0;
        foreach (j; 0 .. len) ++buckets[(xs[work[j]] >> 16) + 1];
        foreach (h; 0 .. 0x10000) buckets[h + 1] += buckets[h];
        foreach (j; 0 .. len) js[buckets[xs[work[j]] >> 16]++] = work[j];
        
        debug {
          if (qL / L < 10) {
            writeln("js = ", js[0 .. min(len, 10)]);
          }
        }
        for (int i = 0, j = 0; j < len; ++j) {
          for (; i < N && A[i] < xs[js[j]]; ++i) {}
          ans[js[j]] = i;
        }
        foreach (q; qL .. qR) {
          ansSum ^= cast(long)(ans[q - qL]) * q;
        }
      }
      writeln(ansSum);
    }
  } catch (EOFException e) {
  }
}
0