結果
問題 | No.973 余興 |
ユーザー |
|
提出日時 | 2020-01-17 22:28:25 |
言語 | D (dmd 2.109.1) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,687 bytes |
コンパイル時間 | 833 ms |
コンパイル使用メモリ | 119,528 KB |
実行使用メモリ | 1,381,352 KB |
最終ジャッジ日時 | 2024-06-22 04:14:53 |
合計ジャッジ時間 | 11,420 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 2 |
other | MLE * 1 -- * 53 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;import std.typecons, std.range, std.random, std.math, std.container;import std.numeric, std.bigint, core.bitop, core.stdc.stdio;void main() {auto s = readln.split.map!(to!int);auto N = s[0];auto X = s[1].to!long;auto A = readln.split.map!(to!long).array;auto B = new long[](N+1);foreach (i; 0..N) B[i+1] = B[i] + A[i];long sum(int l, int r) {if (r < l) return 0;return B[r+1] - B[l];}alias SegTree = SegmentTree!(int, (a,b)=>a+b, 0);auto rst = new SegTree[](N);auto cst = new SegTree[](N);foreach (i; 0..N) rst[i] = new SegTree(N);foreach (i; 0..N) cst[i] = new SegTree(N);int calc_left(int l, int r) {int hi = r + 1;int lo = l;while (hi - lo > 1) {int mid = (hi + lo) / 2;if (sum(l, mid) <= X) lo = mid;else hi = mid;}return lo;}int calc_right(int l, int r) {int hi = r;int lo = l - 1;while (hi - lo > 1) {int mid = (hi + lo) / 2;if (sum(mid, r) <= X) hi = mid;else lo = mid;}return hi;}foreach (len; 2..N+1) foreach (l; 0..N-len+1) {int r = l + len - 1;auto nr = calc_left(l, r) + 1;auto nl = calc_right(l, r) - 1;auto x = rst[l].query(l + 1, nr) != nr - l;auto y = cst[r].query(nl, r - 1) != r - nl;auto z = x | y;rst[l].add(r, 1);cst[r].add(l, 1);}writeln(rst[0].query(N-1, N-1) == 1 ? "A" : "B");}class SegmentTree(T, alias op, T e) {T[] table;int size;int offset;this(int n) {size = 1;while (size <= n) size <<= 1;size <<= 1;table = new T[](size);fill(table, e);offset = size / 2;}void assign(int pos, T val) {pos += offset;table[pos] = val;while (pos > 1) {pos /= 2;table[pos] = op(table[pos*2], table[pos*2+1]);}}void add(int pos, T val) {pos += offset;table[pos] += val;while (pos > 1) {pos /= 2;table[pos] = op(table[pos*2], table[pos*2+1]);}}T query(int l, int r) {return query(l, r, 1, 0, offset-1);}T query(int l, int r, int i, int a, int b) {if (b < l || r < a) {return e;} else if (l <= a && b <= r) {return table[i];} else {return op(query(l, r, i*2, a, (a+b)/2), query(l, r, i*2+1, (a+b)/2+1, b));}}}