結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー koba-e964koba-e964
提出日時 2016-11-18 23:57:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 288 ms / 5,000 ms
コード長 4,183 bytes
コンパイル時間 1,393 ms
コンパイル使用メモリ 123,712 KB
実行使用メモリ 46,916 KB
最終ジャッジ日時 2023-10-23 14:58:17
合計ジャッジ時間 11,945 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 2 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 217 ms
12,028 KB
testcase_13 AC 254 ms
21,940 KB
testcase_14 AC 257 ms
20,008 KB
testcase_15 AC 241 ms
22,788 KB
testcase_16 AC 257 ms
20,836 KB
testcase_17 AC 250 ms
21,104 KB
testcase_18 AC 214 ms
12,028 KB
testcase_19 AC 262 ms
19,996 KB
testcase_20 AC 249 ms
20,004 KB
testcase_21 AC 246 ms
21,948 KB
testcase_22 AC 243 ms
21,940 KB
testcase_23 AC 219 ms
12,028 KB
testcase_24 AC 255 ms
20,848 KB
testcase_25 AC 225 ms
10,600 KB
testcase_26 AC 233 ms
9,116 KB
testcase_27 AC 242 ms
21,932 KB
testcase_28 AC 243 ms
21,960 KB
testcase_29 AC 267 ms
20,016 KB
testcase_30 AC 243 ms
22,788 KB
testcase_31 AC 246 ms
21,936 KB
testcase_32 AC 257 ms
20,004 KB
testcase_33 AC 257 ms
21,112 KB
testcase_34 AC 227 ms
10,600 KB
testcase_35 AC 240 ms
22,800 KB
testcase_36 AC 225 ms
10,596 KB
testcase_37 AC 288 ms
46,916 KB
testcase_38 AC 273 ms
26,576 KB
testcase_39 AC 238 ms
26,576 KB
testcase_40 AC 243 ms
26,576 KB
testcase_41 AC 248 ms
30,272 KB
testcase_42 AC 255 ms
30,272 KB
testcase_43 AC 214 ms
10,928 KB
testcase_44 AC 179 ms
14,412 KB
testcase_45 AC 227 ms
46,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

/**
 * Segment Tree. This data structure is useful for fast folding on intervals of an array
 * whose elements are elements of monoid M. Note that constructing this tree requires the identity
 * element of M and the operation of M.
 * Header requirement: vector, algorithm
 * Verified by AtCoder ABC017-D (http://abc017.contest.atcoder.jp/submissions/660402)
 */
template<class I, class BiOp = I (*) (I, I)>
class SegTree {
  int n;
  std::vector<I> dat;
  BiOp op;
  I e;
public:
  SegTree(int n_, BiOp op, I e) : op(op), e(e) {
    n = 1;
    while (n < n_) { n *= 2; } // n is a power of 2
    dat.resize(2 * n);
    for (int i = 0; i < 2 * n - 1; i++) {
      dat[i] = e;
    }
  }
  /* ary[k] <- v */
  void update(int k, I v) {
    k += n - 1;
    dat[k] = v;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = op(dat[2 * k + 1], dat[2 * k + 2]);
    }
  }
  void update_array(int k, int len, const I *vals) {
    for (int i = 0; i < len; ++i) {
      update(k + i, vals[i]);
    }
  }
  /*
    Updates all elements. O(n)
   */
  void update_all(const I *vals, int len) {
    for (int k = 0; k < std::min(n, len); ++k) {
      dat[k + n - 1] = vals[k];
    }
    for (int k = std::min(n, len); k < n; ++k) {
      dat[k + n - 1] = e;
    }
    for (int b = n / 2; b >= 1; b /= 2) {
      for (int k = 0; k < b; ++k) {
	dat[k + b - 1] = op(dat[k * 2 + b * 2 - 1], dat[k * 2 + b * 2]);
      }
    }
  }
  /* l,r are for simplicity */
  I querySub(int a, int b, int k, int l, int r) const {
    // [a,b) and  [l,r) intersects?
    if (r <= a || b <= l) return e;
    if (a <= l && r <= b) return dat[k];
    I vl = querySub(a, b, 2 * k + 1, l, (l + r) / 2);
    I vr = querySub(a, b, 2 * k + 2, (l + r) / 2, r);
    return op(vl, vr);
  }
  /* [a, b] (note: inclusive) */
  I query(int a, int b) const {
    return querySub(a, b + 1, 0, 0, n);
  }
};


const int N = 30;
int l[N];

int n;

map<string, int> memo;
vector<string> inv;
vector<VI> score;
vector<int> lastmod;
vector<int> sum;

int get(const string &s) {
  if (memo.count(s)) {
    return memo[s];
  }
  int idx = inv.size();
  memo[s] = idx;
  inv.push_back(s);
  score.push_back(VI(n, 0));
  lastmod.push_back(0);
  sum.push_back(0);
  return idx;
}

int main(void){
  cin >> n;
  REP(i, 0, n) {
    cin >> l[i];
  }
  int t;
  cin >> t;
  VI already(n, 0);
  typedef pair<ll, ll> PL;
  vector<PL> events;
  VL sorter;

  REP(i, 0, t) {
    string name, p;
    cin >> name >> p;
    int v = get(name);
    if (p == "?") {
      events.push_back(PL(v, -1));
      continue;
    }
    int id = p[0] - 'A';
    int diff = l[id];
    already[id]++;
    int sc = 50 * diff + (500 * diff) / (8 + 2 * already[id]);
    score[v][id] = sc;
    lastmod[v] = i;
    sum[v] += sc;
    events.push_back(PL(v, (ll)sum[v] * 1e9 - i));
    sorter.push_back((ll)sum[v] * 1e9 - i);
  }
  sort(sorter.begin(), sorter.end());
  map<ll, int> sinv;
  REP(i, 0, sorter.size()) {
    sinv[sorter[i]] = i;
  }
  REP(i, 0, events.size()) {
    if (events[i].second >= 0) {
      events[i].second = sinv[events[i].second];
    }
  }
  SegTree<int, plus<int> > st(2 * t, plus<int>(), 0);
  VL cur(inv.size(), -1);
  REP(i, 0, events.size()) {
    int v = events[i].first;
    int sc = events[i].second;
    if (0) {
      cerr << "query: " << v << " " << sc << endl;
    }
    if (sc >= 0) {
      if (cur[v] >= 0) {
	st.update(cur[v], st.query(cur[v], cur[v]) - 1);
      }
      st.update(sc, st.query(sc, sc) + 1);
      cur[v] = sc;
    } else {
      cout << 1 + st.query(cur[v] + 1, 2 * t) << endl;
    }
  }
}
0