結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー kzyKTkzyKT
提出日時 2016-11-19 00:00:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 207 ms / 5,000 ms
コード長 1,548 bytes
コンパイル時間 1,618 ms
コンパイル使用メモリ 180,900 KB
実行使用メモリ 31,996 KB
最終ジャッジ日時 2023-10-23 14:59:29
合計ジャッジ時間 9,302 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
12,944 KB
testcase_01 AC 5 ms
12,944 KB
testcase_02 AC 4 ms
12,940 KB
testcase_03 AC 5 ms
13,008 KB
testcase_04 AC 5 ms
13,000 KB
testcase_05 AC 5 ms
13,008 KB
testcase_06 AC 6 ms
13,004 KB
testcase_07 AC 5 ms
13,000 KB
testcase_08 AC 5 ms
13,000 KB
testcase_09 AC 5 ms
13,004 KB
testcase_10 AC 5 ms
13,000 KB
testcase_11 AC 5 ms
13,000 KB
testcase_12 AC 123 ms
15,264 KB
testcase_13 AC 158 ms
20,576 KB
testcase_14 AC 183 ms
19,660 KB
testcase_15 AC 147 ms
21,012 KB
testcase_16 AC 170 ms
19,960 KB
testcase_17 AC 171 ms
19,968 KB
testcase_18 AC 122 ms
15,264 KB
testcase_19 AC 202 ms
19,660 KB
testcase_20 AC 186 ms
19,656 KB
testcase_21 AC 160 ms
20,424 KB
testcase_22 AC 159 ms
20,576 KB
testcase_23 AC 121 ms
15,264 KB
testcase_24 AC 172 ms
19,956 KB
testcase_25 AC 142 ms
14,484 KB
testcase_26 AC 161 ms
13,856 KB
testcase_27 AC 159 ms
20,412 KB
testcase_28 AC 160 ms
20,424 KB
testcase_29 AC 207 ms
19,656 KB
testcase_30 AC 146 ms
21,016 KB
testcase_31 AC 163 ms
20,576 KB
testcase_32 AC 185 ms
19,660 KB
testcase_33 AC 171 ms
19,972 KB
testcase_34 AC 144 ms
14,484 KB
testcase_35 AC 148 ms
21,020 KB
testcase_36 AC 148 ms
14,484 KB
testcase_37 AC 191 ms
31,996 KB
testcase_38 AC 191 ms
22,364 KB
testcase_39 AC 165 ms
22,364 KB
testcase_40 AC 166 ms
22,364 KB
testcase_41 AC 160 ms
25,168 KB
testcase_42 AC 163 ms
25,168 KB
testcase_43 AC 117 ms
14,584 KB
testcase_44 AC 70 ms
16,144 KB
testcase_45 AC 141 ms
31,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
ll bit[500010];
class BIT{
public:
  ll n;
  BIT(){fill(bit,bit+500010,0);}
  void add(ll i,ll x){
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
  ll sum(ll i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
};
bool cmp(PP a, PP b) {
  if(a.F==b.F) return a.S.F<b.S.F;
  return a.F>b.F;
}

P p[111111];
ll d[111111];
vector<PP> a;
vector<ll> c[111111];
ll b[111111];

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  ll n,m;
  cin >> n;
  int aa[n],bb[n];
  for(int i=0;i<n;i++) cin >> aa[i];
  cin >> m;
  memset(bb,0,sizeof(bb));
  map<string,int> mm;ll k=0;
  for(int i=0; i<m; i++) {
    string s;
    char c;
    ll x,y;
    cin >> s >> c;
    if(!mm.count(s)) {
      mm[s]=k;
      k++;
    }
    x=mm[s];
    if(c=='?') y=-1;
    else {
      y=c-'A';
      bb[y]++;
      int z=50*aa[y]+50*aa[y]/(0.8+0.2*bb[y]);
      d[x]+=z;
      a.push_back(PP(d[x],P(i,x)));
    }
    p[i]=P(y,x);
  }
  for(int i=0; i<k; i++) a.push_back(PP(0,P(-1,i)));
  BIT t=BIT();
  t.n=a.size();
  sort(a.begin(),a.end(),cmp);
  for(int i=a.size()-1; i>=0; i--) c[a[i].S.S].push_back(i+1);
  for(int i=0; i<k; i++) {
    t.add(c[i][b[i]],1);
    b[i]++;
  }
  for(int i=0; i<m; i++) {
    ll x=p[i].S;
    if(p[i].F>=0) {
      t.add(c[x][b[x]-1],-1);
      t.add(c[x][b[x]],1);
      b[x]++;
    } else cout << t.sum(c[x][b[x]-1]) << endl;
  }
  return 0;
}
0