結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー tubo28tubo28
提出日時 2016-11-19 17:37:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 187 ms / 5,000 ms
コード長 11,634 bytes
コンパイル時間 2,298 ms
コンパイル使用メモリ 191,696 KB
実行使用メモリ 24,148 KB
最終ジャッジ日時 2023-10-23 15:54:52
合計ジャッジ時間 9,380 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 119 ms
12,000 KB
testcase_13 AC 167 ms
14,560 KB
testcase_14 AC 134 ms
14,428 KB
testcase_15 AC 178 ms
15,096 KB
testcase_16 AC 157 ms
14,420 KB
testcase_17 AC 161 ms
14,436 KB
testcase_18 AC 117 ms
11,996 KB
testcase_19 AC 137 ms
14,432 KB
testcase_20 AC 138 ms
14,416 KB
testcase_21 AC 171 ms
14,564 KB
testcase_22 AC 166 ms
14,564 KB
testcase_23 AC 123 ms
11,996 KB
testcase_24 AC 148 ms
14,424 KB
testcase_25 AC 98 ms
12,000 KB
testcase_26 AC 79 ms
9,952 KB
testcase_27 AC 168 ms
14,564 KB
testcase_28 AC 166 ms
14,564 KB
testcase_29 AC 137 ms
14,416 KB
testcase_30 AC 187 ms
15,116 KB
testcase_31 AC 170 ms
14,564 KB
testcase_32 AC 138 ms
14,424 KB
testcase_33 AC 149 ms
14,436 KB
testcase_34 AC 100 ms
12,000 KB
testcase_35 AC 181 ms
15,160 KB
testcase_36 AC 100 ms
12,000 KB
testcase_37 AC 174 ms
24,148 KB
testcase_38 AC 125 ms
17,132 KB
testcase_39 AC 107 ms
17,132 KB
testcase_40 AC 109 ms
17,132 KB
testcase_41 AC 158 ms
18,444 KB
testcase_42 AC 164 ms
18,444 KB
testcase_43 AC 88 ms
11,956 KB
testcase_44 AC 124 ms
12,972 KB
testcase_45 AC 178 ms
24,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <tuple>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <string>

#include <bits/stdc++.h>
//using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) std::cerr << __LINE__ << ":\t" #x " = " << x << std::endl


using Key = long long; // score, lastsub, user

struct Node {
    Key key;
    int priority;
    Node *left, *right;
    int size;
    Key min;

    static Node * const NIL;

    Node() { }

    Node(const Key &x)
        : Node(x, rand(), NIL, NIL, 1, x) { }

    Node(const Key &key_, int priority_,
         Node *left_, Node *right_, int size_, const Key &min_)
        : key(key_), priority(priority_),
          left(left_), right(right_), size(size_), min(min_) { }

    void *operator new(std::size_t){
        static Node pool[200010];
        static int p = 0;
        return pool + p++;
    }
};

using Np = Node*;
using CNp = const Node*;
using pair = std::pair<Np, Np>;

const Key INF = 1e18;
Node * const Node::NIL = new Node(Key(), -1, nullptr, nullptr, 0, INF);

class treap {
protected:
    Np root;

public:
    treap()
        : root(Node::NIL) { }

    treap(Np root_)
        : root(root_) { }

public:
    void assign_at(int k, Key x) {
        __assign_at(root, k, x);
    }

protected:
    void __assign_at(Np n, int k, Key x) {
        if (k < n->left->size) {
            __assign_at(n->left, k, x);
        } else if (n->left->size == k) {
            n->key = x;
        } else {
            __assign_at(n->right, k - n->left->size - 1, x);
        }
        __update(n);
    }

public:
    Key range_min(int l, int r) {
        return __range_min(root, l, r);
    }

protected:
    Key __range_min(CNp n, int l, int r) const {
        l = std::max(l, 0);
        r = std::min(r, n->size);
        if (l >= r) return INF;
        if (l == 0 && r == n->size) return n->min;
        Key res = INF;
        int sl = n->left->size;
        res = std::min(res, __range_min(n->left, l, r));
        res = std::min(res, __range_min(n->right, l - sl - 1, r - sl - 1));
        if (l <= sl && sl < r) res = std::min(res, n->key);
        return res;
    }

public:
    void merge_from_left(treap &t) {
        root = __merge(t.root, root);
    }

    void merge_from_right(treap &t) {
        root = __merge(root, t.root);
    }

protected:
    Np __merge(Np l, Np r) const {
        if (l == Node::NIL) return r;
        if (r == Node::NIL) return l;
        if (l->priority > r->priority) {
            l->right = __merge(l->right, r);
            return __update(l);
        } else {
            r->left = __merge(l, r->left);
            return __update(r);
        }
    }

public:
    std::pair<treap, treap> split_at(int k) {
        Np l, r;
        std::tie(l, r) = __split_at(root, k);
        return std::make_pair(treap(l), treap(r));
    }

protected:
    pair __split_at(Np n, int k) const {
        if (n == Node::NIL) return{ Node::NIL, Node::NIL };
        if (k <= n->left->size) {
            pair p = __split_at(n->left, k);
            n->left = p.second;
            return pair(p.first, __update(n));
        } else {
            pair p = __split_at(n->right, k - n->left->size - 1);
            n->right = p.first;
            return pair(__update(n), p.second);
        }
    }

public:
    void insert_at(const Key &x, int k) {
        root = __insert_at(root, x, k);
    }

protected:
    Np __insert_at(Np n, const Key &x, int k) const {
        Np l, r;
        std::tie(l, r) = __split_at(n, k);
        return __merge(__merge(l, new Node(x)), r);
    }

public:
    void erase_at(int k) {
        root = __erase_at(root, k);
    }

protected:
    Np __erase_at(Np n, int k) const {
        Np l,r,m;
        std::tie(l, r) = __split_at(n, k);
        std::tie(r, m) = __split_at(r, 1);
        return __merge(l, r);
    }

public:
    const Key &front() const {
        assert(root != Node::NIL);
        return __front(root)->key;
    }

protected:
    CNp __front(CNp n) const {
        return n->left != Node::NIL ? __front(n->left) : n;
    }

public:
    const Key &back(CNp n) const {
        assert(n != Node::NIL);
        return __back(root)->key;
    }

protected:
    CNp __back(CNp n) const {
        return n->right != Node::NIL ? __back(n->right) : n;
    }

public:
    Key front() {
        assert(root != Node::NIL);
        return __front(root)->key;
    }

protected:
    Np __front(Np n) const {
        return n->left != Node::NIL ? __front(n->left) : n;
    }

public:
    Key back(CNp n) {
        assert(n != Node::NIL);
        return __back(root)->key;
    }

protected:
    Np __back(Np n) const {
        return n->right != Node::NIL ? __back(n->right) : n;
    }

public:
    void push_front(Key k) {
        root = __merge(new Node(k, rand(), Node::NIL, Node::NIL, 1, k), root);
    }

    void push_back(Key k) {
        root = __merge(root, new Node(k, rand(), Node::NIL, Node::NIL, 1, k));
    }

    void pop_front() {
        assert(root->size != 0);
        root = __split_at(root, 1).first;
    }

    void pop_back() {
        assert(root->size != 0);
        root = __split_at(root, root->size - 1).second;
    }

protected:
    Np __update(Np n) const {
        n->size = 1 + n->left->size + n->right->size;
        n->min = std::min({ n->left->min, n->key, n->right->min });
        return n;
    }

public:
    std::string to_string() const {
        std::string res;
        __to_string(root, res);
        return res;
    }

protected:
    void __to_string(CNp n, std::string &res) const {
        res += "(";
        if(n != Node::NIL) {
            __to_string(n->left, res);
            res += ")" + std::to_string(n->key) + "(";
            __to_string(n->right, res);
        }
        res += ")";
    }
};

// ソートされた列を管理
class ordered_set : public treap {
public:
    ordered_set() : treap() {}
    ordered_set(Node *n) : treap(n) {}

public:    
    std::pair<ordered_set, ordered_set> split_at(int k) {
        Np l, r;
        std::tie(l, r) = __split_at(root, k);
        return std::make_pair(ordered_set(l), ordered_set(r));
    }
    
public:
    // x未満とx以上に分割
    std::pair<ordered_set, ordered_set> split_less(const Key &x) {
        Np l, r;
        std::tie(l, r) = __split_less(root, x);
        return std::make_pair(ordered_set(l), ordered_set(r));
    }

protected:
    pair __split_less(Np n, const Key &x) const {
        if (n == Node::NIL) return pair(Node::NIL, Node::NIL);
        if (n->key < x) {
            pair p = __split_less(n->right, x);
            n->right = p.first;
            return pair(__update(n), p.second);
        } else {
            pair p = __split_less(n->left, x);
            n->left = p.second;
            return pair(p.first, __update(n));
        }
    }

public:
    // x未満とx以上に分割
    std::pair<ordered_set, ordered_set> split_leq(const Key &x) {
        Np l, r;
        std::tie(l, r) = __split_leq(root, x);
        return std::make_pair(ordered_set(l), ordered_set(r));
    }

protected:
    pair __split_leq(Np n, const Key &x) const {
        if (n == Node::NIL) return pair(Node::NIL, Node::NIL);
        if (n->key <= x) {
            pair p = __split_leq(n->right, x);
            n->right = p.first;
            return pair(__update(n), p.second);
        } else {
            pair p = __split_leq(n->left, x);
            n->left = p.second;
            return pair(p.first, __update(n));
        }
    }

public:
    void insert(const Key &x) {
        root = __insert(root, x);
    }

protected:
    Np __insert(Np n, const Key &x) const {
        Np l, r;
        std::tie(l, r) = __split_less(n, x);
        return __merge(__merge(l, new Node(x)), r);
    }

public:
    void erase_one(const Key &x) {
        assert(includes(x));
        root = __erase_one(root, x);
    }

protected:
    Np __erase_one(Np n, const Key &x) const {
        Np l, m, r;
        std::tie(l, r) = __split_less(n, x);
        std::tie(m, r) = __split_at(r, 1);
        return __merge(l, r);
    }

public:
    void erase_all(const Key &x) {
        root = __erase_one(root, x);
    }

protected:
    Np __erase_all(Np n, const Key &x) const {
        Np l, m, r;
        std::tie(l, r) = __split_less(root, x);
        std::tie(m, r) = __split_leq(r, x);
        return __merge(l, r);
    }

public:
    int count_less(const Key &x) const {
        return __count_less(root, x);
    }

protected:
    int __count_less(CNp n, const Key &x) const {
        if(n == Node::NIL) return 0;
        int res = 0;
        if(n->key < x){
            res += n->left->size;
            res += 1;
            res += __count_less(n->right, x);
        } else {
            res += __count_less(n->left, x);
        }
        return res;
    }

public:
    int count_leq(const Key &x) const {
        return __count_leq(root, x);
    }

protected:
    int __count_leq(CNp n, const Key &x) const {
        if(n == Node::NIL) return 0;
        int res = 0;
        if(n->key <= x){
            res += n->left->size;
            res += 1;
            res += __count_less(n->right, x);
        } else {
            res += __count_less(n->left, x);
        }
        return res;
    }

public:
    int count(const Key &x) const {
        return count_leq(x) - count_less(x);
    }

public:
    bool includes(const Key &x) const {
        return __includes(root, x);
    }

protected:
    bool __includes(Np n, const Key &x) const {
        if(n == Node::NIL) return false;
        else if(n->key < x) return __includes(n->right, x);
        else if(n->key == x) return true;
        else return __includes(n->left, x);
    }

public:
    Key lower_bound(const Key &x) const {
        return __lower_bound(root, x)->key;
    }

protected:
    Np __lower_bound(Np n, const Key &x) const {
        if(n == Node::NIL) return Node::NIL;
        if(n->key <= x){
            Np res = __lower_bound(n->left, x);
            return res != Node::NIL ? res : n;
        } else {
            return __lower_bound(n->right, x);
        }
    }

public:
    Key upper_bound(const Key &x) const {
        return __upper_bound(root, x)->key;
    }

protected:
    Np __upper_bound(Np n, const Key &x) const {
        if(n == Node::NIL) return Node::NIL;
        if(n->key < x){
            Np res = __upper_bound(n->left, x);
            return res != Node::NIL ? res : n;
        } else {
            return __upper_bound(n->right, x);
        }
    }
};

using namespace std;

int N;
int star[30];
int T;

int solved[30];
// user->
int score[100010], lastsub[100010];

unordered_map<string,int> f;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    cin >> N;
    rep(i,N) cin >> star[i];
    cin >> T;
    int id = 0;

    ordered_set tree;

    rep(i,T) tree.insert(0);

    rep(i,T){
        string name;
        cin >> name;
        auto res = f.emplace(name, id);
        if(res.second) res.first->second = id++;
        int man = res.first->second;
        char str[10];
        cin >> str;
        Key cur = -score[man]*1000000000LL + lastsub[man];
        if(str[0] == '?'){
            int ord = tree.count_less(cur);
            cout << ord + 1 << '\n';
        } else {
            int prob = str[0] - 'A';
            int s = 50*star[prob] + 50*star[prob] / (0.8 + 0.2*(solved[prob]+1));
            ++solved[prob];
            score[man] += s;
            lastsub[man] = i;
            auto nxt = -score[man]*1000000000LL +lastsub[man];
            tree.erase_one(cur);
            tree.insert(nxt);
        }
    }
}
0