結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー r_dream0r_dream0
提出日時 2017-02-28 20:13:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 194 ms / 5,000 ms
コード長 1,982 bytes
コンパイル時間 1,146 ms
コンパイル使用メモリ 96,712 KB
実行使用メモリ 22,852 KB
最終ジャッジ日時 2023-10-23 16:05:33
合計ジャッジ時間 9,246 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 135 ms
5,348 KB
testcase_13 AC 142 ms
9,132 KB
testcase_14 AC 171 ms
8,868 KB
testcase_15 AC 129 ms
9,396 KB
testcase_16 AC 154 ms
8,868 KB
testcase_17 AC 158 ms
9,132 KB
testcase_18 AC 138 ms
5,348 KB
testcase_19 AC 173 ms
8,868 KB
testcase_20 AC 166 ms
8,872 KB
testcase_21 AC 145 ms
9,136 KB
testcase_22 AC 152 ms
9,140 KB
testcase_23 AC 135 ms
5,348 KB
testcase_24 AC 163 ms
9,136 KB
testcase_25 AC 158 ms
4,824 KB
testcase_26 AC 177 ms
4,820 KB
testcase_27 AC 144 ms
9,132 KB
testcase_28 AC 148 ms
9,132 KB
testcase_29 AC 174 ms
8,872 KB
testcase_30 AC 139 ms
9,400 KB
testcase_31 AC 146 ms
9,140 KB
testcase_32 AC 168 ms
8,868 KB
testcase_33 AC 172 ms
9,136 KB
testcase_34 AC 157 ms
4,824 KB
testcase_35 AC 134 ms
9,400 KB
testcase_36 AC 159 ms
4,824 KB
testcase_37 AC 175 ms
22,852 KB
testcase_38 AC 194 ms
13,420 KB
testcase_39 AC 180 ms
13,420 KB
testcase_40 AC 180 ms
13,420 KB
testcase_41 AC 135 ms
14,212 KB
testcase_42 AC 136 ms
14,212 KB
testcase_43 AC 156 ms
5,048 KB
testcase_44 AC 112 ms
5,524 KB
testcase_45 AC 179 ms
22,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <vector>
using namespace std;

struct BIT{
  vector<int> bit;int size;
  BIT(int n){
    size=n;bit=vector<int>(n+1);
  }
  //a[i]=x
  void add(int i,int x){
    i+=1;
    while(i<=size)bit[i]+=x,i+=i&-i;
  }
  //a[k] (k<i)の要素の和を求める
  int sum(int i){
    int s=0;
    while(i>0)s+=bit[i],i-=i&-i;
    return s;
  }
};

inline int calc_score(int stars, int users) {
  return 50 * stars + (500 * stars) / (8 + 2 * (users + 1));
}

int main() {
  int N, T;
  cin >> N;
  vector<int> L(N);
  for(int i = 0; i < N; i++) cin >> L[i];
  cin >> T;
  vector<string> names;
  unordered_map<string, int> name_to_id;
  vector<int> id, query;
  for(int i = 0; i < T; i++) {
    string name, P;
    cin >> name >> P;
    if(!name_to_id.count(name)) {
      name_to_id[name] = names.size();
      names.push_back(name);
    }
    id.push_back(name_to_id[name]);
    query.push_back(P == "?" ? -1 : P[0] - 'A');
  }
  vector<int> score(names.size());
  vector<int> scores(1);
  vector<int> solved(N);
  for(int i = 0; i < T; i++) {
    if(query[i] == -1) continue;
    score[id[i]] = (score[id[i]] / T + calc_score(L[query[i]], solved[query[i]])) * T + T - i - 1;
    scores.push_back(score[id[i]]);
    solved[query[i]]++;
  }
  std::sort(scores.begin(), scores.end());
  BIT bit(scores.size());
  solved = vector<int>(N);
  score = vector<int>(names.size());
for(int i = 0; i < T; i++) {
    if(query[i] == -1) {
      int lid = lower_bound(scores.begin(), scores.end(), score[id[i]]) - scores.begin();
      cout << bit.sum(scores.size()) - bit.sum(lid + 1) + 1 << endl;
      continue;
    }
    bit.add(lower_bound(scores.begin(), scores.end(), score[id[i]]) - scores.begin(), -1);
    score[id[i]] = (score[id[i]] / T + calc_score(L[query[i]], solved[query[i]])) * T + T - i - 1;
    bit.add(lower_bound(scores.begin(), scores.end(), score[id[i]]) - scores.begin(), 1);
    solved[query[i]]++;
  }
}
0