結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー kimiyukikimiyuki
提出日時 2016-11-24 23:39:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,390 ms / 5,000 ms
コード長 2,514 bytes
コンパイル時間 1,384 ms
コンパイル使用メモリ 95,184 KB
実行使用メモリ 18,640 KB
最終ジャッジ日時 2023-10-23 16:00:14
合計ジャッジ時間 12,458 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 4 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 157 ms
10,468 KB
testcase_13 AC 174 ms
10,940 KB
testcase_14 AC 213 ms
11,052 KB
testcase_15 AC 151 ms
10,940 KB
testcase_16 AC 192 ms
10,940 KB
testcase_17 AC 190 ms
10,940 KB
testcase_18 AC 158 ms
10,440 KB
testcase_19 AC 208 ms
11,028 KB
testcase_20 AC 219 ms
10,940 KB
testcase_21 AC 177 ms
10,940 KB
testcase_22 AC 177 ms
10,940 KB
testcase_23 AC 160 ms
10,424 KB
testcase_24 AC 196 ms
11,056 KB
testcase_25 AC 183 ms
10,456 KB
testcase_26 AC 204 ms
10,412 KB
testcase_27 AC 178 ms
10,940 KB
testcase_28 AC 180 ms
11,100 KB
testcase_29 AC 214 ms
10,996 KB
testcase_30 AC 155 ms
11,092 KB
testcase_31 AC 171 ms
11,160 KB
testcase_32 AC 239 ms
11,204 KB
testcase_33 AC 227 ms
11,284 KB
testcase_34 AC 184 ms
10,676 KB
testcase_35 AC 164 ms
11,204 KB
testcase_36 AC 182 ms
10,676 KB
testcase_37 AC 173 ms
18,640 KB
testcase_38 AC 827 ms
18,184 KB
testcase_39 AC 188 ms
17,540 KB
testcase_40 AC 1,390 ms
17,540 KB
testcase_41 AC 263 ms
18,444 KB
testcase_42 AC 755 ms
18,444 KB
testcase_43 AC 191 ms
18,068 KB
testcase_44 AC 128 ms
18,068 KB
testcase_45 AC 142 ms
18,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using namespace std;
template <typename T> T sortunique(T xs) { whole(sort, xs); xs.erase(whole(unique, xs), xs.end()); return xs; }
template <typename T> int index(vector<T> const & xs, T x) { return whole(lower_bound, xs, x) - xs.begin(); }
template <typename T>
struct binary_indexed_tree { // on monoid
    vector<T> data;
    T unit;
    function<T (T,T)> append; // associative
    template <typename F>
    binary_indexed_tree(size_t n, T a_unit, F a_append) : data(n, a_unit), unit(a_unit), append(a_append) {}
    void point_append(size_t i, T w) { // data[i] += w
        for (size_t j = i+1; j <= data.size(); j += j & -j) data[j-1] = append(data[j-1], w);
    }
    int initial_range_concat(size_t i) { // sum [0, i)
        T acc = unit;
        for (size_t j = i; 0 < j; j -= j & -j) acc = append(acc, data[j-1]);
        return acc;
    }
};
int scoreof(int level, int solved) {
    assert (solved >= 1);
    return 50*level + 250*level/(4+solved);
}
int main() {
    // input
    int n; cin >> n;
    vector<int> level(n);
    repeat (i,n) cin >> level[i];
    int query; cin >> query;
    vector<string> name(query);
    vector<char> action(query);
    repeat (t,query) cin >> name[t] >> action[t];
    // prepare
    const int max_score = 100 * whole(accumulate, level, 0);
    vector<string> ids = sortunique(name);
    int m = ids.size();
    // answer
    vector<int> solved(n);
    vector<int> score(m);
    binary_indexed_tree<int> bit(max_score + 1, int(), plus<int>());
    bit.point_append(0, m);
    vector<vector<int> > tiebreak(max_score + 1);
    repeat (t,query) {
        int id = index(ids, name[t]);
        int j = score[id];
        if (action[t] == '?') {
            int a = bit.initial_range_concat(j);
            int b = tiebreak[j].size() - (whole(find, tiebreak[j], id) - tiebreak[j].begin()) - 1;
            cout << m-a-b << endl;
        } else {
            bit.point_append(j, -1);
            if (j) tiebreak[j].erase(whole(find, tiebreak[j], id));
            int i = action[t] - 'A';
            solved[i] += 1;
            j = score[id] += scoreof(level[i], solved[i]);
            bit.point_append(j, +1);
            tiebreak[j].push_back(id);
        }
    }
    return 0;
}
0