結果
問題 | No.1786 Maximum Suffix Median (Online) |
ユーザー | 👑 hos.lyric |
提出日時 | 2021-12-15 00:55:08 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 1,444 ms / 2,000 ms |
コード長 | 2,774 bytes |
コンパイル時間 | 866 ms |
コンパイル使用メモリ | 107,288 KB |
実行使用メモリ | 229,592 KB |
最終ジャッジ日時 | 2023-09-04 15:22:36 |
合計ジャッジ時間 | 28,987 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,384 KB |
testcase_02 | AC | 1 ms
4,384 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,384 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 1,349 ms
205,340 KB |
testcase_09 | AC | 978 ms
148,468 KB |
testcase_10 | AC | 1,030 ms
161,460 KB |
testcase_11 | AC | 875 ms
134,636 KB |
testcase_12 | AC | 1,378 ms
215,200 KB |
testcase_13 | AC | 1,068 ms
204,892 KB |
testcase_14 | AC | 837 ms
159,996 KB |
testcase_15 | AC | 924 ms
178,232 KB |
testcase_16 | AC | 949 ms
183,964 KB |
testcase_17 | AC | 848 ms
156,932 KB |
testcase_18 | AC | 1,421 ms
227,688 KB |
testcase_19 | AC | 1,444 ms
227,908 KB |
testcase_20 | AC | 1,431 ms
227,684 KB |
testcase_21 | AC | 1,441 ms
227,804 KB |
testcase_22 | AC | 1,442 ms
229,592 KB |
testcase_23 | AC | 940 ms
183,112 KB |
testcase_24 | AC | 714 ms
138,236 KB |
testcase_25 | AC | 1,050 ms
209,956 KB |
testcase_26 | AC | 932 ms
187,304 KB |
testcase_27 | AC | 860 ms
172,212 KB |
testcase_28 | AC | 992 ms
200,504 KB |
testcase_29 | AC | 1 ms
4,380 KB |
testcase_30 | AC | 2 ms
4,380 KB |
testcase_31 | AC | 590 ms
23,176 KB |
testcase_32 | AC | 585 ms
23,132 KB |
ソースコード
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)); } enum INF = 10^^9; class Node { Node L, R; // x -> max(x + lzp, lzq) int mx; int lzp, lzq; this() { mx = 0; lzp = 0; lzq = -INF; } void ch(int p, int q) { mx = max(mx + p, q); lzp += p; lzq = max(lzq + p, q); } void push() { L.ch(lzp, lzq); R.ch(lzp, lzq); lzp = 0; lzq = -INF; } void merge() { mx = max(L.mx, R.mx); } void update(int l, int r, int a, int b, int p, int q) { if (b <= l || r <= a) { return; } if (a <= l && r <= b) { ch(p, q); return; } if (!L) L = new Node; if (!R) R = new Node; push(); const mid = (l + r) >> 1; L.update(l, mid, a, b, p, q); R.update(mid, r, a, b, p, q); merge(); } int solve(int l, int r) { assert(mx > 0); if (!L || !R) { assert(!L && !R); return r - 1; } push(); // writefln("solve [%s,%s) R.mx = %s",l,r,R?R.mx.to!string:"null"); const mid = (l + r) >> 1; const ret = (R.mx > 0) ? R.solve(mid, r) : L.solve(l, mid); merge(); return ret; } }; enum E = 30; void main() { try { for (; ; ) { const N = readInt; auto A = new int[N]; foreach (i; 0 .. N) { A[i] = readInt; } long ans; auto seg = new Node; foreach (i; 0 .. N) { A[i] ^= ans; seg.update(0, 1 << E, 0, A[i] + 1, 1, 0); seg.update(0, 1 << E, A[i] + 1, 1 << E, -1, 0); ans = seg.solve(0, 1 << E); writeln(ans); } debug { writeln("A = ", A); } // break; } } catch (EOFException e) { } }