結果
問題 | No.449 ゆきこーだーの雨と雪 (4) |
ユーザー | koba-e964 |
提出日時 | 2016-11-19 00:36:47 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 287 ms / 5,000 ms |
コード長 | 2,928 bytes |
コンパイル時間 | 1,367 ms |
コンパイル使用メモリ | 99,424 KB |
実行使用メモリ | 45,172 KB |
最終ジャッジ日時 | 2024-09-22 10:18:40 |
合計ジャッジ時間 | 10,788 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 3 ms
6,944 KB |
testcase_04 | AC | 3 ms
6,944 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 | 3 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 3 ms
6,944 KB |
testcase_12 | AC | 185 ms
10,936 KB |
testcase_13 | AC | 226 ms
20,772 KB |
testcase_14 | AC | 238 ms
19,024 KB |
testcase_15 | AC | 221 ms
21,592 KB |
testcase_16 | AC | 240 ms
19,828 KB |
testcase_17 | AC | 226 ms
19,956 KB |
testcase_18 | AC | 181 ms
10,936 KB |
testcase_19 | AC | 244 ms
19,012 KB |
testcase_20 | AC | 234 ms
18,892 KB |
testcase_21 | AC | 232 ms
20,780 KB |
testcase_22 | AC | 224 ms
20,648 KB |
testcase_23 | AC | 180 ms
10,940 KB |
testcase_24 | AC | 231 ms
19,912 KB |
testcase_25 | AC | 192 ms
9,544 KB |
testcase_26 | AC | 203 ms
8,100 KB |
testcase_27 | AC | 227 ms
20,764 KB |
testcase_28 | AC | 227 ms
20,796 KB |
testcase_29 | AC | 232 ms
18,900 KB |
testcase_30 | AC | 215 ms
21,724 KB |
testcase_31 | AC | 233 ms
20,768 KB |
testcase_32 | AC | 234 ms
19,024 KB |
testcase_33 | AC | 229 ms
19,972 KB |
testcase_34 | AC | 195 ms
9,544 KB |
testcase_35 | AC | 216 ms
21,732 KB |
testcase_36 | AC | 196 ms
9,504 KB |
testcase_37 | AC | 287 ms
45,172 KB |
testcase_38 | AC | 271 ms
25,432 KB |
testcase_39 | AC | 228 ms
25,436 KB |
testcase_40 | AC | 236 ms
25,436 KB |
testcase_41 | AC | 240 ms
29,148 KB |
testcase_42 | AC | 246 ms
29,268 KB |
testcase_43 | AC | 183 ms
9,980 KB |
testcase_44 | AC | 150 ms
13,240 KB |
testcase_45 | AC | 218 ms
45,100 KB |
ソースコード
#include <algorithm> #include <cassert> #include <iostream> #include <map> #include <string> #include <vector> #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) using namespace std; typedef long long int ll; typedef vector<int> VI; typedef vector<ll> VL; typedef pair<int, int> PI; /** * Binary Indexed Tree (Fenwick Tree). Holds an array of type T. * T is a commutative monoid. Indices are 1 .. n. * Verified by AtCoder ARC043 C (http://arc043.contest.atcoder.jp/submissions/985157) */ template <class T, class Op> class BIT { private: int n; std::vector<T> ary; Op op; T e; public: BIT(int n, Op op = Op(), T e = T()) : op(op), e(e) { assert (n > 0); while(n != (n & (-n))) { // find the least power of 2 >= n n += n & (-n); } this->n = n; ary = std::vector<T>(n + 1); for(int i = 0; i <= n; i++) { ary[i] = e; } } /** * gets the sum in [1 .. idx] * @param idx * @return sum */ T accum(int idx) { T sum = e; while(idx > 0) { sum = op(sum, ary[idx]); idx &= idx - 1; } return sum; } /** * performs data[idx] += val; */ void add(int idx, T val) { assert (idx > 0); while(idx <= n) { ary[idx] = op(ary[idx], val); idx += idx & (-idx); } } }; int l[30]; int n; map<string, int> memo; vector<string> inv; vector<VI> score; vector<int> lastmod; vector<int> sum; int get(const string &s) { if (memo.count(s)) { return memo[s]; } int idx = inv.size(); memo[s] = idx; inv.push_back(s); score.push_back(VI(n, 0)); lastmod.push_back(0); sum.push_back(0); return idx; } int main(void){ cin >> n; REP(i, 0, n) { cin >> l[i]; } int t; cin >> t; VI already(n, 0); typedef pair<ll, ll> PL; vector<PL> events; VL sorter; REP(i, 0, t) { string name, p; cin >> name >> p; int v = get(name); if (p == "?") { events.push_back(PL(v, -1)); continue; } int id = p[0] - 'A'; int diff = l[id]; already[id]++; int sc = 50 * diff + (500 * diff) / (8 + 2 * already[id]); score[v][id] = sc; lastmod[v] = i; sum[v] += sc; events.push_back(PL(v, (ll)sum[v] * 1e9 - i)); sorter.push_back((ll)sum[v] * 1e9 - i); } sort(sorter.begin(), sorter.end()); map<ll, int> sinv; REP(i, 0, sorter.size()) { sinv[sorter[i]] = i; } REP(i, 0, events.size()) { if (events[i].second >= 0) { events[i].second = sinv[events[i].second]; } } BIT<int, plus<int> > bit(2 * t + 1); VL cur(inv.size(), -1); REP(i, 0, events.size()) { int v = events[i].first; int sc = events[i].second; if (0) { cerr << "query: " << v << " " << sc << endl; } if (sc >= 0) { if (cur[v] >= 0) { bit.add(cur[v] + 1, -1); } bit.add(sc + 1, 1); cur[v] = sc; } else { cout << 1 + bit.accum(2 * t) - bit.accum(cur[v] + 1) << endl; } } }