結果
問題 | No.449 ゆきこーだーの雨と雪 (4) |
ユーザー | nebukuro09 |
提出日時 | 2016-11-21 20:43:40 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 259 ms / 5,000 ms |
コード長 | 2,531 bytes |
コンパイル時間 | 1,062 ms |
コンパイル使用メモリ | 128,728 KB |
実行使用メモリ | 32,648 KB |
最終ジャッジ日時 | 2024-06-12 05:10:06 |
合計ジャッジ時間 | 11,766 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 3 ms
6,940 KB |
testcase_04 | AC | 3 ms
6,940 KB |
testcase_05 | AC | 3 ms
6,940 KB |
testcase_06 | AC | 3 ms
6,940 KB |
testcase_07 | AC | 3 ms
6,940 KB |
testcase_08 | AC | 3 ms
6,940 KB |
testcase_09 | AC | 4 ms
6,940 KB |
testcase_10 | AC | 4 ms
6,940 KB |
testcase_11 | AC | 3 ms
6,944 KB |
testcase_12 | AC | 182 ms
17,884 KB |
testcase_13 | AC | 210 ms
23,120 KB |
testcase_14 | AC | 183 ms
22,652 KB |
testcase_15 | AC | 238 ms
22,980 KB |
testcase_16 | AC | 198 ms
23,740 KB |
testcase_17 | AC | 193 ms
22,188 KB |
testcase_18 | AC | 186 ms
19,460 KB |
testcase_19 | AC | 187 ms
22,652 KB |
testcase_20 | AC | 187 ms
23,020 KB |
testcase_21 | AC | 205 ms
22,604 KB |
testcase_22 | AC | 210 ms
22,304 KB |
testcase_23 | AC | 184 ms
18,496 KB |
testcase_24 | AC | 201 ms
22,440 KB |
testcase_25 | AC | 175 ms
17,332 KB |
testcase_26 | AC | 151 ms
14,984 KB |
testcase_27 | AC | 218 ms
24,024 KB |
testcase_28 | AC | 222 ms
22,656 KB |
testcase_29 | AC | 196 ms
22,852 KB |
testcase_30 | AC | 259 ms
24,044 KB |
testcase_31 | AC | 239 ms
23,128 KB |
testcase_32 | AC | 192 ms
22,244 KB |
testcase_33 | AC | 219 ms
22,944 KB |
testcase_34 | AC | 176 ms
19,052 KB |
testcase_35 | AC | 248 ms
23,256 KB |
testcase_36 | AC | 178 ms
17,488 KB |
testcase_37 | AC | 197 ms
31,136 KB |
testcase_38 | AC | 177 ms
27,148 KB |
testcase_39 | AC | 162 ms
27,032 KB |
testcase_40 | AC | 162 ms
27,108 KB |
testcase_41 | AC | 219 ms
28,368 KB |
testcase_42 | AC | 223 ms
28,296 KB |
testcase_43 | AC | 179 ms
18,260 KB |
testcase_44 | AC | 209 ms
18,904 KB |
testcase_45 | AC | 201 ms
32,648 KB |
ソースコード
import std.stdio; import std.array; import std.string; import std.conv; import std.algorithm; import std.typecons; import std.range; import std.random; import std.math; import std.container; class SegmentTree { int[] table; int N, table_size; this(int n) { N = n; table_size = 1; while (table_size < n) table_size *= 2; table_size *= 2; table = new int[](table_size); } void add(int pos, int num) { add_rec(0, 0, table_size/2-1, pos, num); } void add_rec(int i, int left, int right, int pos, int num) { table[i] += num; if (left == right) return; auto mid = (left + right) / 2; if (pos <= mid) add_rec(i*2+1, left, mid, pos, num); else add_rec(i*2+2, mid+1, right, pos, num); } int sum(int pl, int pr) { return sum_rec(0, pl, pr, 0, table_size/2-1); } int sum_rec(int i, int pl, int pr, int left, int right) { if (pl > right || pr < left) return 0; else if (pl <= left && right <= pr) return table[i]; else return sum_rec(i*2+1, pl, pr, left, (left+right)/2) + sum_rec(i*2+2, pl, pr, (left+right)/2+1, right); } } void main() { auto score(int a, int b) {return 50*a + 500*a/(8+2*b);}; alias Tuple!(int, "score", int, "order") Point; auto N = readln.chomp.to!int; auto L = readln.split.map!(to!int); Point[string] participants; Point[] points; auto ACed = new int[](N); auto T = readln.chomp.to!int; auto NP = new Tuple!(string, int, int)[](T); foreach (i; 0..T) { auto input = readln.split; if (input[1] == "?") { NP[i] = tuple(input[0], -1, -1); continue; } auto name = input[0]; auto prob = input[1][0].to!int - 'A'.to!int; ACed[prob] += 1; if (name in participants) participants[name] = Point(participants[name].score + score(L[prob], ACed[prob]), i); else participants[name] = Point(score(L[prob], ACed[prob]), i); points ~= Point(-participants[name].score, i); NP[i] = tuple(name, participants[name].score, i); } points.sort(); int[Point] ranks; foreach (i, p; points.enumerate) ranks[Point(-p.score, p.order)] = i.to!int; auto sg = new SegmentTree(100000); int[string] last; foreach (i; 0..T) { if (NP[i][2] == -1) { writeln(sg.sum(0, last[NP[i][0]])); } else { auto name = NP[i][0]; auto rank = ranks[Point(NP[i][1], NP[i][2])]; if (name in last) sg.add(last[name], -1); last[name] = rank; sg.add(rank, 1); } } }