結果
問題 | No.1786 Maximum Suffix Median (Online) |
ユーザー | 👑 hos.lyric |
提出日時 | 2021-12-15 00:29:38 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 1,555 ms / 2,000 ms |
コード長 | 2,761 bytes |
コンパイル時間 | 792 ms |
コンパイル使用メモリ | 107,304 KB |
実行使用メモリ | 238,920 KB |
最終ジャッジ日時 | 2023-09-04 15:21:09 |
合計ジャッジ時間 | 32,054 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,384 KB |
testcase_03 | AC | 2 ms
4,384 KB |
testcase_04 | AC | 2 ms
4,384 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,388 KB |
testcase_08 | AC | 1,339 ms
215,148 KB |
testcase_09 | AC | 994 ms
154,860 KB |
testcase_10 | AC | 1,080 ms
167,884 KB |
testcase_11 | AC | 926 ms
141,528 KB |
testcase_12 | AC | 1,418 ms
224,620 KB |
testcase_13 | AC | 1,138 ms
222,084 KB |
testcase_14 | AC | 903 ms
172,732 KB |
testcase_15 | AC | 999 ms
193,160 KB |
testcase_16 | AC | 1,034 ms
199,100 KB |
testcase_17 | AC | 891 ms
169,616 KB |
testcase_18 | AC | 1,488 ms
237,504 KB |
testcase_19 | AC | 1,504 ms
238,832 KB |
testcase_20 | AC | 1,555 ms
238,764 KB |
testcase_21 | AC | 1,495 ms
238,920 KB |
testcase_22 | AC | 1,527 ms
237,576 KB |
testcase_23 | AC | 1,017 ms
198,276 KB |
testcase_24 | AC | 779 ms
148,152 KB |
testcase_25 | AC | 1,145 ms
227,920 KB |
testcase_26 | AC | 1,014 ms
194,840 KB |
testcase_27 | AC | 944 ms
179,024 KB |
testcase_28 | AC | 1,092 ms
207,008 KB |
testcase_29 | AC | 2 ms
4,384 KB |
testcase_30 | AC | 1 ms
4,384 KB |
testcase_31 | AC | 711 ms
23,216 KB |
testcase_32 | AC | 704 ms
23,128 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() { if (!L) L = new Node; if (!R) R = new Node; 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; } 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 (r - l == 1) { return l; } push(); // writefln("solve [%s,%s) R.mx = %s",l,r,R?R.mx.to!string:"null"); const mid = (l + r) >> 1; const ret = (R && R.mx > 0) ? R.solve(mid, r) : L ? L.solve(l, mid) : l; 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) { } }