結果
| 問題 |
No.961 Vibrant Fillumination
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-25 10:29:20 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 591 ms / 5,000 ms |
| コード長 | 5,476 bytes |
| コンパイル時間 | 1,270 ms |
| コンパイル使用メモリ | 142,668 KB |
| 実行使用メモリ | 16,320 KB |
| 最終ジャッジ日時 | 2024-06-22 04:01:12 |
| 合計ジャッジ時間 | 28,696 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 48 |
ソースコード
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) {
}
}