結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー hashiryohashiryo
提出日時 2019-06-27 17:27:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 284 ms / 5,000 ms
コード長 2,937 bytes
コンパイル時間 2,163 ms
コンパイル使用メモリ 180,540 KB
実行使用メモリ 125,312 KB
最終ジャッジ日時 2023-10-23 16:11:27
合計ジャッジ時間 12,705 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,208 KB
testcase_01 AC 4 ms
5,212 KB
testcase_02 AC 3 ms
5,208 KB
testcase_03 AC 6 ms
5,588 KB
testcase_04 AC 5 ms
5,540 KB
testcase_05 AC 5 ms
5,608 KB
testcase_06 AC 4 ms
5,496 KB
testcase_07 AC 6 ms
5,548 KB
testcase_08 AC 4 ms
5,500 KB
testcase_09 AC 5 ms
5,544 KB
testcase_10 AC 5 ms
5,480 KB
testcase_11 AC 5 ms
5,488 KB
testcase_12 AC 251 ms
41,592 KB
testcase_13 AC 263 ms
32,496 KB
testcase_14 AC 274 ms
22,944 KB
testcase_15 AC 261 ms
37,644 KB
testcase_16 AC 272 ms
27,760 KB
testcase_17 AC 273 ms
28,104 KB
testcase_18 AC 252 ms
41,324 KB
testcase_19 AC 284 ms
23,188 KB
testcase_20 AC 282 ms
22,560 KB
testcase_21 AC 265 ms
32,144 KB
testcase_22 AC 272 ms
32,580 KB
testcase_23 AC 251 ms
42,428 KB
testcase_24 AC 280 ms
27,696 KB
testcase_25 AC 258 ms
30,504 KB
testcase_26 AC 253 ms
18,556 KB
testcase_27 AC 267 ms
31,672 KB
testcase_28 AC 258 ms
32,448 KB
testcase_29 AC 270 ms
22,836 KB
testcase_30 AC 249 ms
37,168 KB
testcase_31 AC 263 ms
33,200 KB
testcase_32 AC 262 ms
21,368 KB
testcase_33 AC 258 ms
25,380 KB
testcase_34 AC 257 ms
32,152 KB
testcase_35 AC 255 ms
35,976 KB
testcase_36 AC 283 ms
32,204 KB
testcase_37 AC 192 ms
25,548 KB
testcase_38 AC 228 ms
15,392 KB
testcase_39 AC 184 ms
15,392 KB
testcase_40 AC 186 ms
15,392 KB
testcase_41 AC 181 ms
20,100 KB
testcase_42 AC 189 ms
20,116 KB
testcase_43 AC 258 ms
72,052 KB
testcase_44 AC 254 ms
125,312 KB
testcase_45 AC 126 ms
25,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/2;
const ll MOD = 1e9+7;
const double EPS=1e-12;

template<typename KEYTYPE = unsigned long long, int B = 64>
class BinaryTrie {
    struct node {
        int cnt;
        KEYTYPE lazy;
        node *ch[2];
        node() : cnt(0), lazy(0), ch{ nullptr, nullptr } {}
    };
    node* insert_node(node* t, KEYTYPE key, int b = B - 1) {
        if (!t) t = new node;
        t->cnt += 1;
        if (b < 0) return t;
        push(t, b);
        bool f = (key >> (KEYTYPE)b) & (KEYTYPE)1;
        t->ch[f] = insert_node(t->ch[f], key, b - 1);
        return t;
    }
    node* erase_node(node* t, KEYTYPE key, int b = B - 1) {
        assert(t);
        t->cnt -= 1;
        if (t->cnt == 0) return nullptr;
        if (b < 0) return t;
        push(t, b);
        bool f = (key >> (KEYTYPE)b) & (KEYTYPE)1;
        t->ch[f] = erase_node(t->ch[f], key, b - 1);
        return t;
    }
    //[
    void push(node* t, int b) {
        if ((t->lazy >> (KEYTYPE)b) & (KEYTYPE)1) swap(t->ch[0], t->ch[1]);
        if (t->ch[0]) t->ch[0]->lazy ^= t->lazy;
        if (t->ch[1]) t->ch[1]->lazy ^= t->lazy;
        t->lazy = 0;
    }
    int count_lower(node* t, KEYTYPE key, int b = B - 1) {
        if (!t || b < 0) return 0;
        push(t, b);
        bool f = (key >> (KEYTYPE)b) & (KEYTYPE)1;
        return (f && t->ch[0] ? t->ch[0]->cnt : 0) + count_lower(t->ch[f], key, b - 1);
    }
    //]
    node *root;
public:
    BinaryTrie() : root(nullptr) {}
    int size() const {
        return root ? root->cnt : 0;
    }
    void insert(KEYTYPE key) {
        root = insert_node(root, key);
    }
    void erase(KEYTYPE key) {
        root = erase_node(root, key);
    }
    int lower_bound(KEYTYPE key) { // return id
        return count_lower(root, key);
    }
};

int id(string name){
  static int cnt=0;
  static map<string,int> mp;
  if(mp.count(name)==0){
    mp[name]=cnt++;
    return cnt-1;
  }else{
    return mp[name];
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;cin>>N;
  ll L[N];
  for(ll i=0;i<N;i++)cin>>L[i];
  ll score[100010]={};
  ll lastup[100010]={};
  ll ac[N]={};
  ll T;cin>>T;
  BinaryTrie<> S;
  for(ll t=1;t<=T;t++){
    string Name;char P;cin>>Name>>P;
    ll idx=id(Name);
    if(P=='?'){
      //debug(S.size());
      cout<<S.size()-S.lower_bound(score[idx]*T+T-lastup[idx])<<endl;
    }else{
      //debug(lastup[idx]);
      //debug(idx);
      if(lastup[idx]>0)S.erase(score[idx]*T+T-lastup[idx]);
      score[idx]+=50*L[P-'A']+50*L[P-'A']*10/(8+2*++ac[P-'A']);
      lastup[idx]=t;
      S.insert(score[idx]*T+T-lastup[idx]);
    }
  }
  return 0;
}
0