結果
問題 | No.449 ゆきこーだーの雨と雪 (4) |
ユーザー |
|
提出日時 | 2016-11-24 23:39:44 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,386 ms / 5,000 ms |
コード長 | 2,514 bytes |
コンパイル時間 | 1,497 ms |
コンパイル使用メモリ | 96,136 KB |
実行使用メモリ | 18,612 KB |
最終ジャッジ日時 | 2024-09-22 10:28:38 |
合計ジャッジ時間 | 12,161 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <numeric>#include <functional>#include <cassert>#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)using namespace std;template <typename T> T sortunique(T xs) { whole(sort, xs); xs.erase(whole(unique, xs), xs.end()); return xs; }template <typename T> int index(vector<T> const & xs, T x) { return whole(lower_bound, xs, x) - xs.begin(); }template <typename T>struct binary_indexed_tree { // on monoidvector<T> data;T unit;function<T (T,T)> append; // associativetemplate <typename F>binary_indexed_tree(size_t n, T a_unit, F a_append) : data(n, a_unit), unit(a_unit), append(a_append) {}void point_append(size_t i, T w) { // data[i] += wfor (size_t j = i+1; j <= data.size(); j += j & -j) data[j-1] = append(data[j-1], w);}int initial_range_concat(size_t i) { // sum [0, i)T acc = unit;for (size_t j = i; 0 < j; j -= j & -j) acc = append(acc, data[j-1]);return acc;}};int scoreof(int level, int solved) {assert (solved >= 1);return 50*level + 250*level/(4+solved);}int main() {// inputint n; cin >> n;vector<int> level(n);repeat (i,n) cin >> level[i];int query; cin >> query;vector<string> name(query);vector<char> action(query);repeat (t,query) cin >> name[t] >> action[t];// prepareconst int max_score = 100 * whole(accumulate, level, 0);vector<string> ids = sortunique(name);int m = ids.size();// answervector<int> solved(n);vector<int> score(m);binary_indexed_tree<int> bit(max_score + 1, int(), plus<int>());bit.point_append(0, m);vector<vector<int> > tiebreak(max_score + 1);repeat (t,query) {int id = index(ids, name[t]);int j = score[id];if (action[t] == '?') {int a = bit.initial_range_concat(j);int b = tiebreak[j].size() - (whole(find, tiebreak[j], id) - tiebreak[j].begin()) - 1;cout << m-a-b << endl;} else {bit.point_append(j, -1);if (j) tiebreak[j].erase(whole(find, tiebreak[j], id));int i = action[t] - 'A';solved[i] += 1;j = score[id] += scoreof(level[i], solved[i]);bit.point_append(j, +1);tiebreak[j].push_back(id);}}return 0;}