結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー tubo28tubo28
提出日時 2016-11-19 17:46:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 219 ms / 5,000 ms
コード長 11,998 bytes
コンパイル時間 1,938 ms
コンパイル使用メモリ 185,544 KB
実行使用メモリ 24,176 KB
最終ジャッジ日時 2023-10-23 15:55:51
合計ジャッジ時間 9,670 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
13,164 KB
testcase_01 AC 5 ms
13,164 KB
testcase_02 AC 6 ms
13,160 KB
testcase_03 AC 7 ms
13,192 KB
testcase_04 AC 7 ms
13,192 KB
testcase_05 AC 6 ms
13,192 KB
testcase_06 AC 7 ms
13,192 KB
testcase_07 AC 6 ms
13,192 KB
testcase_08 AC 7 ms
13,192 KB
testcase_09 AC 7 ms
13,192 KB
testcase_10 AC 7 ms
13,192 KB
testcase_11 AC 6 ms
13,192 KB
testcase_12 AC 129 ms
13,432 KB
testcase_13 AC 192 ms
15,992 KB
testcase_14 AC 153 ms
15,860 KB
testcase_15 AC 216 ms
15,864 KB
testcase_16 AC 172 ms
15,852 KB
testcase_17 AC 183 ms
15,868 KB
testcase_18 AC 157 ms
13,428 KB
testcase_19 AC 159 ms
15,864 KB
testcase_20 AC 155 ms
15,848 KB
testcase_21 AC 205 ms
15,856 KB
testcase_22 AC 200 ms
15,872 KB
testcase_23 AC 138 ms
13,428 KB
testcase_24 AC 177 ms
15,856 KB
testcase_25 AC 117 ms
13,432 KB
testcase_26 AC 87 ms
13,432 KB
testcase_27 AC 192 ms
15,864 KB
testcase_28 AC 195 ms
15,868 KB
testcase_29 AC 145 ms
15,848 KB
testcase_30 AC 219 ms
15,864 KB
testcase_31 AC 205 ms
15,872 KB
testcase_32 AC 147 ms
15,856 KB
testcase_33 AC 155 ms
15,868 KB
testcase_34 AC 112 ms
13,432 KB
testcase_35 AC 213 ms
15,868 KB
testcase_36 AC 109 ms
13,432 KB
testcase_37 AC 202 ms
24,176 KB
testcase_38 AC 134 ms
18,564 KB
testcase_39 AC 127 ms
18,564 KB
testcase_40 AC 127 ms
18,564 KB
testcase_41 AC 195 ms
18,564 KB
testcase_42 AC 177 ms
18,564 KB
testcase_43 AC 94 ms
13,388 KB
testcase_44 AC 114 ms
13,564 KB
testcase_45 AC 200 ms
24,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#ifdef _MSC_VER
#include <process.h>
#else
#include <sys/types.h>
#include <unistd.h>
#endif

using Key = std::pair<int,int>;
const Key INF = Key(1e9, 1e9);

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

    static Node * const NIL;

    Node() { }

    Node(const Key &x)
        : Node(x, xor128(), 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++;
    }

    static uint32_t xor128() {
        static uint32_t x = 123456789, y = 362436069, z = 521288629, w = time(0);
        uint32_t t = x ^ (x << 11);
        x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
        return w;
    }
};

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

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, Node::xor128(), Node::NIL, Node::NIL, 1, k), root);
    }

    void push_back(Key k) {
        root = __merge(root, new Node(k, Node::xor128(), 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(n, 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);
        }
    }
};


#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

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(make_pair(0,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], 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 = make_pair(-score[man], lastsub[man]);
            tree.erase_one(cur);
            tree.insert(nxt);
        }
    }
}
0