結果

問題 No.961 Vibrant Fillumination
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-12-25 10:29:20
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 653 ms / 5,000 ms
コード長 5,476 bytes
コンパイル時間 1,203 ms
コンパイル使用メモリ 126,776 KB
実行使用メモリ 16,376 KB
最終ジャッジ日時 2023-09-04 04:29:20
合計ジャッジ時間 30,497 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 510 ms
14,912 KB
testcase_03 AC 533 ms
16,104 KB
testcase_04 AC 520 ms
15,548 KB
testcase_05 AC 526 ms
14,872 KB
testcase_06 AC 502 ms
15,112 KB
testcase_07 AC 524 ms
15,268 KB
testcase_08 AC 518 ms
15,476 KB
testcase_09 AC 512 ms
15,428 KB
testcase_10 AC 639 ms
15,580 KB
testcase_11 AC 641 ms
15,236 KB
testcase_12 AC 652 ms
15,416 KB
testcase_13 AC 623 ms
15,000 KB
testcase_14 AC 653 ms
16,060 KB
testcase_15 AC 596 ms
15,532 KB
testcase_16 AC 614 ms
15,136 KB
testcase_17 AC 598 ms
15,472 KB
testcase_18 AC 653 ms
16,040 KB
testcase_19 AC 627 ms
15,136 KB
testcase_20 AC 630 ms
14,804 KB
testcase_21 AC 582 ms
14,824 KB
testcase_22 AC 595 ms
15,804 KB
testcase_23 AC 595 ms
15,256 KB
testcase_24 AC 631 ms
16,048 KB
testcase_25 AC 639 ms
15,508 KB
testcase_26 AC 380 ms
16,108 KB
testcase_27 AC 353 ms
16,352 KB
testcase_28 AC 373 ms
15,164 KB
testcase_29 AC 368 ms
15,528 KB
testcase_30 AC 290 ms
16,100 KB
testcase_31 AC 190 ms
15,140 KB
testcase_32 AC 458 ms
14,988 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 553 ms
14,848 KB
testcase_35 AC 529 ms
15,548 KB
testcase_36 AC 544 ms
16,056 KB
testcase_37 AC 553 ms
15,200 KB
testcase_38 AC 514 ms
15,428 KB
testcase_39 AC 539 ms
15,796 KB
testcase_40 AC 538 ms
15,176 KB
testcase_41 AC 533 ms
15,512 KB
testcase_42 AC 524 ms
15,088 KB
testcase_43 AC 546 ms
16,376 KB
testcase_44 AC 546 ms
15,876 KB
testcase_45 AC 526 ms
15,192 KB
testcase_46 AC 531 ms
15,324 KB
testcase_47 AC 529 ms
15,536 KB
testcase_48 AC 550 ms
15,536 KB
testcase_49 AC 529 ms
15,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, 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 N = readInt();
      auto H = new long[N];
      foreach (k; 0 .. N) {
        H[k] = readLong();
      }
      auto A = new int[N];
      auto B = new int[N];
      auto C = new int[N];
      auto D = new int[N];
      auto E = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
        B[i] = readInt();
        C[i] = readInt();
        D[i] = readInt();
        E[i] = readInt() - 1;
      }
      auto Q = readInt();
      auto X = new int[Q];
      auto Y = new int[Q];
      foreach (q; 0 .. Q) {
        X[q] = readInt();
        Y[q] = readInt();
      }
      
      alias Entry = Tuple!(int, "pos", int, "id");
      auto xs = new Entry[N + N];
      auto ys = new Entry[N + N];
      foreach (i; 0 .. N) {
        xs[i] = Entry(A[i], i);
        ys[i] = Entry(B[i], i);
        xs[N + i] = Entry(C[i], N + i);
        ys[N + i] = Entry(D[i], N + i);
      }
      xs.sort;
      ys.sort;
      auto as = new int[N];
      auto bs = new int[N];
      auto cs = new int[N];
      auto ds = new int[N];
      foreach (e; 0 .. N + N) {
        if (xs[e].id < N) {
          as[xs[e].id] = e;
        } else {
          cs[xs[e].id - N] = e;
        }
      }
      foreach (f; 0 .. N + N) {
        if (ys[f].id < N) {
          bs[ys[f].id] = f;
        } else {
          ds[ys[f].id - N] = f;
        }
      }
      debug {
        writeln("xs = ", xs);
        writeln("ys = ", ys);
        writeln("as = ", as);
        writeln("bs = ", bs);
        writeln("cs = ", cs);
        writeln("ds = ", ds);
      }
      
      const L = cast(int)((N + N)^^0.5L);
      
      alias Query = Tuple!(int, "e", int, "f", int, "id");
      auto queries = new Query[Q];
      foreach (q; 0 .. Q) {
        const e = xs.upperBound(Entry(X[q], N + N));
        const f = ys.upperBound(Entry(Y[q], N + N));
        queries[q] = Query(e, f, q);
      }
      queries.sort!((a, b) => ((a.e / L != b.e / L) ? (a.e / L < b.e / L)
                                                    : (a.e / L % 2 == 0) ? (a.f < b.f) : (a.f > b.f)));
      
      auto cnt = new int[N];
      long now;
      void add(int i) {
        if (cnt[E[i]]++ == 0) {
          now ^= H[E[i]];
        }
      }
      void rem(int i) {
        if (--cnt[E[i]] == 0) {
          now ^= H[E[i]];
        }
      }
      
      auto ans = new long[Q];
      {
        int e, f;
        foreach (qry; queries) {
          /*
                    |
                    |
            f-------+--
                    |
              (e,f) |
                    |
                    e
          */
          for (; e < qry.e; ++e) {
            if (xs[e].id < N) {
              const i = xs[e].id;
              if (bs[i] < f && f <= ds[i]) add(i);
            } else {
              const i = xs[e].id - N;
              if (bs[i] < f && f <= ds[i]) rem(i);
            }
            debug {
              writeln("++e: ", cnt);
            }
          }
          for (; e > qry.e; --e) {
            if (xs[e - 1].id < N) {
              const i = xs[e - 1].id;
              if (bs[i] < f && f <= ds[i]) rem(i);
            } else {
              const i = xs[e - 1].id - N;
              if (bs[i] < f && f <= ds[i]) add(i);
            }
            debug {
              writeln("--e: ", cnt);
            }
          }
          for (; f < qry.f; ++f) {
            if (ys[f].id < N) {
              const i = ys[f].id;
              if (as[i] < e && e <= cs[i]) add(i);
            } else {
              const i = ys[f].id - N;
              if (as[i] < e && e <= cs[i]) rem(i);
            }
            debug {
              writeln("++f: ", cnt);
            }
          }
          for (; f > qry.f; --f) {
            if (ys[f - 1].id < N) {
              const i = ys[f - 1].id;
              if (as[i] < e && e <= cs[i]) rem(i);
            } else {
              const i = ys[f - 1].id - N;
              if (as[i] < e && e <= cs[i]) add(i);
            }
            debug {
              writeln("--f: ", cnt);
            }
          }
          debug {
            writeln("qry = ", qry);
          }
          ans[qry.id] = now;
        }
      }
      foreach (q; 0 .. Q) {
        writeln(ans[q]);
      }
    }
  } catch (EOFException e) {
  }
}
0