結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー parukiparuki
提出日時 2016-11-19 00:16:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,625 bytes
コンパイル時間 2,861 ms
コンパイル使用メモリ 205,176 KB
実行使用メモリ 814,784 KB
最終ジャッジ日時 2023-10-23 15:01:06
合計ジャッジ時間 5,097 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template<class Val>
struct BinaryIndexedTree{
    int n;
    vector<Val> t;
    BinaryIndexedTree(){}
    BinaryIndexedTree(int _n):n(_n+1), t(_n+1){}
    void add(int k, Val val){
        k++;
        while(k < n){
            t[k] += val;
            k += (k&-k);
        }
    }
    Val sum(int k){
        Val r = 0;
        while(k > 0){
            r += t[k];
            k -= (k&-k);
        }
        return r;
    }
    Val sum(int l, int r){
        return sum(r) - sum(l);
    }
};
typedef BinaryIndexedTree<int> BIT;

int f(int x, int y) {
    return 50 * x + 500 * x / (8 + 2 * y);
}

int MA = 600000001;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    while(cin >> N) {
        BIT sum(MA);

        vi L(N);
        vi cnt(N);

        map<string, int> pt;
        rep(i, N) {
            cin >> L[i];
        }

        // ポイント=>pair<名前、時刻>
        map<int, set<pair<string, int>>> ptn;

        int T;
        cin >> T;
        rep(i, T) {
            string name;
            char c;
            cin >> name >> c;
            
            if(c == '?') {
                int x = pt[name];
                int rank = sum.sum(x + 1, MA);
                vector<pair<int, string>> v;
                each(p, ptn[pt[name]]) {
                    v.emplace_back(p.second, p.first);
                }
                sort(all(v));
                rep(j, sz(v)) {
                    ++rank;
                    if(v[j].second == name) {
                        break;
                    }
                }
                cout << rank << endl;
            } else {
                int p = c - 'A';
                // f(L[p], ++cnt[p]);
                if(pt.count(name)) {
                    sum.add(pt[name], -1);
                    auto it = ptn[pt[name]].lower_bound(mp(name, 0));
                    ptn[pt[name]].erase(it);
                }
                pt[name] += f(L[p], ++cnt[p]);
                sum.add(pt[name], 1);
                
                ptn[pt[name]].insert(mp(name, i));
            }
        }
    }
}
0