結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー kimiyukikimiyuki
提出日時 2016-11-24 23:22:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,466 bytes
コンパイル時間 1,818 ms
コンパイル使用メモリ 113,176 KB
実行使用メモリ 25,436 KB
最終ジャッジ日時 2023-10-23 16:00:01
合計ジャッジ時間 10,589 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 180 ms
25,436 KB
testcase_38 AC 236 ms
20,420 KB
testcase_39 AC 203 ms
20,396 KB
testcase_40 AC 202 ms
20,564 KB
testcase_41 AC 184 ms
23,324 KB
testcase_42 WA -
testcase_43 AC 217 ms
20,156 KB
testcase_44 AC 175 ms
21,240 KB
testcase_45 AC 165 ms
25,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#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, typename X> auto vectors(T a, X x) { return vector<T>(x, a); }
template <typename T, typename X, typename Y, typename... Zs> auto vectors(T a, X x, Y y, Zs... zs) { auto cont = vectors(a, y, zs...); return vector<decltype(cont)>(x, cont); }
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;
    }
};
double scoreof(int level, int solved) {
    assert (solved >= 1);
    return 50*level + 250*level/(4.0+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
    vector<string> sorted_names = sortunique(name);
    int m = sorted_names.size();
    vector<int> id(query);
    vector<double> sorted_scores; {
        vector<double> found_scores(query + 1);
        vector<double> score(m);
        vector<int> solved(n);
        repeat (t,query) {
            id[t] = index(sorted_names, name[t]);
            if (action[t] != '?') {
                int i = action[t] - 'A';
                solved[i] += 1;
                score[id[t]] += scoreof(level[i], solved[i]);
                found_scores[t] = score[id[t]];
            }
        }
        sorted_scores = sortunique(found_scores);
    }
    // answer
    vector<int> solved(n);
    vector<double> score(m);
    binary_indexed_tree<int> bit(sorted_scores.size(), int(), plus<int>());
    bit.point_append(0, m);
    vector<vector<int> > tiebreak(sorted_scores.size());
    repeat (t,query) {
        int j = index(sorted_scores, score[id[t]]);
        if (action[t] == '?') {
            int a = bit.initial_range_concat(j);
            int b = tiebreak[j].size() - (whole(find, tiebreak[j], id[t]) - 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[t]));
            int i = action[t] - 'A';
            solved[i] += 1;
            score[id[t]] += scoreof(level[i], solved[i]);
            j = index(sorted_scores, score[id[t]]);
            bit.point_append(j, +1);
            tiebreak[j].push_back(id[t]);
        }
    }
    return 0;
}
0