結果
問題 | No.259 セグメントフィッシング+ |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-01-24 16:48:14 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 105 ms / 2,000 ms |
コード長 | 2,645 bytes |
コンパイル時間 | 2,796 ms |
コンパイル使用メモリ | 105,856 KB |
実行使用メモリ | 19,216 KB |
最終ジャッジ日時 | 2023-09-03 23:03:35 |
合計ジャッジ時間 | 5,614 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,384 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,380 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 99 ms
16,480 KB |
testcase_09 | AC | 98 ms
18,600 KB |
testcase_10 | AC | 99 ms
16,800 KB |
testcase_11 | AC | 97 ms
16,508 KB |
testcase_12 | AC | 97 ms
18,524 KB |
testcase_13 | AC | 105 ms
16,768 KB |
testcase_14 | AC | 103 ms
17,340 KB |
testcase_15 | AC | 101 ms
18,432 KB |
testcase_16 | AC | 103 ms
18,084 KB |
testcase_17 | AC | 103 ms
17,844 KB |
testcase_18 | AC | 101 ms
17,040 KB |
testcase_19 | AC | 101 ms
18,648 KB |
testcase_20 | AC | 101 ms
17,308 KB |
testcase_21 | AC | 101 ms
19,216 KB |
testcase_22 | AC | 102 ms
18,088 KB |
testcase_23 | AC | 75 ms
13,412 KB |
testcase_24 | AC | 87 ms
17,076 KB |
testcase_25 | AC | 87 ms
16,760 KB |
ソースコード
import std.conv, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, 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(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; } int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); } int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); } void add(long[] bit, int pos, long val) { for (int x = pos; x < bit.length; x |= x + 1) { bit[x] += val; } } long sum(long[] bit, int pos) { long ret; for (int x = pos - 1; x >= 0; x = (x & (x + 1)) - 1) { ret += bit[x]; } return ret; } int N, Q; string[] X; int[] T, Y, Z; int mod(int a) { return ((a %= (2 * N)) < 0) ? (a + 2 * N) : a; } void main() { try { for (; ; ) { N = readInt(); Q = readInt(); X = new string[Q]; T = new int[Q]; Y = new int[Q]; Z = new int[Q]; foreach (q; 0 .. Q) { X[q] = readToken(); T[q] = readInt(); Y[q] = readInt(); Z[q] = readInt(); } auto bit = new long[2 * N]; foreach (q; 0 .. Q) { switch (X[q]) { case "L": { bit.add(mod((2 * N - 1 - Y[q]) - T[q]), Z[q]); } break; case "R": { bit.add(mod(Y[q] - T[q]), Z[q]); } break; case "C": { --Z[q]; long ans; foreach (p; [ [mod(Y[q] - T[q]), mod(Z[q] - T[q] + 1)], [mod((2 * N - 1 - Z[q]) - T[q]), mod((2 * N - 1 - Y[q]) - T[q] + 1)] ]) { ans -= bit.sum(p[0]); ans += bit.sum(p[1]); if (p[0] > p[1]) { ans += bit.sum(2 * N); } } writeln(ans); } break; default: assert(false); } } } } catch (EOFException e) { } }