結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー parukiparuki
提出日時 2016-11-19 11:30:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 504 ms / 5,000 ms
コード長 2,556 bytes
コンパイル時間 2,328 ms
コンパイル使用メモリ 192,720 KB
実行使用メモリ 34,256 KB
最終ジャッジ日時 2023-10-23 15:55:22
合計ジャッジ時間 14,061 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 3 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 2 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 208 ms
8,140 KB
testcase_13 AC 297 ms
13,788 KB
testcase_14 AC 289 ms
13,368 KB
testcase_15 AC 297 ms
13,852 KB
testcase_16 AC 299 ms
13,652 KB
testcase_17 AC 306 ms
13,684 KB
testcase_18 AC 207 ms
8,132 KB
testcase_19 AC 287 ms
13,340 KB
testcase_20 AC 293 ms
13,336 KB
testcase_21 AC 295 ms
13,764 KB
testcase_22 AC 291 ms
13,800 KB
testcase_23 AC 207 ms
8,124 KB
testcase_24 AC 297 ms
13,680 KB
testcase_25 AC 207 ms
7,956 KB
testcase_26 AC 206 ms
7,560 KB
testcase_27 AC 308 ms
13,764 KB
testcase_28 AC 306 ms
13,776 KB
testcase_29 AC 294 ms
13,344 KB
testcase_30 AC 309 ms
13,860 KB
testcase_31 AC 311 ms
13,796 KB
testcase_32 AC 289 ms
13,364 KB
testcase_33 AC 302 ms
13,696 KB
testcase_34 AC 209 ms
7,976 KB
testcase_35 AC 303 ms
13,884 KB
testcase_36 AC 211 ms
7,992 KB
testcase_37 AC 504 ms
34,256 KB
testcase_38 AC 344 ms
22,808 KB
testcase_39 AC 292 ms
22,808 KB
testcase_40 AC 294 ms
22,808 KB
testcase_41 AC 366 ms
23,320 KB
testcase_42 AC 367 ms
23,320 KB
testcase_43 AC 175 ms
12,244 KB
testcase_44 AC 151 ms
12,984 KB
testcase_45 AC 260 ms
34,256 KB
権限があれば一括ダウンロードができます

ソースコード

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 main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    while(cin >> N) {

        vi L(N);
        vi cnt(N);
        rep(i, N) cin >> L[i];
        int T;
        cin >> T;
        vector<string> Name(T);
        vector<char> P(T);

        map<string, int> pt;
        vector<pii> pos;
        pos.emplace_back(0, 0);

        rep(i, T) {
            cin >> Name[i] >> P[i];
            if(P[i] != '?') {
                P[i] -= 'A';
                pt[Name[i]] += f(L[P[i]], ++cnt[P[i]]);
                pos.emplace_back(pt[Name[i]], -i);
            }
        }

        sort(all(pos));
        BIT sum(sz(pos));
        sum.add(0, sz(pt));
        map<string, int> last;
        pt.clear();
        fill_n(cnt.begin(), N, 0);

        auto g = [&](int p, int las) {
            auto it = lower_bound(all(pos), mp(p, -las));
            assert(it != pos.end());
            return it - pos.begin();
        };

        rep(i, T) {
            if(P[i] != '?') {
                int k = g(pt[Name[i]], last[Name[i]]);
                sum.add(k, -1);
                pt[Name[i]] += f(L[P[i]], ++cnt[P[i]]);
                last[Name[i]] = i;
                k = g(pt[Name[i]], i);
                sum.add(k, 1);
            } else {
                int k = g(pt[Name[i]], last[Name[i]]);
                int ans = sum.sum(k, sz(pos));
                cout << ans << endl;
            }
        }
    }
}
0