結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー startcppstartcpp
提出日時 2016-11-19 00:52:21
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 4,583 bytes
コンパイル時間 1,368 ms
コンパイル使用メモリ 80,376 KB
実行使用メモリ 31,492 KB
最終ジャッジ日時 2023-10-23 15:49:10
合計ジャッジ時間 15,084 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,472 KB
testcase_01 AC 4 ms
10,472 KB
testcase_02 AC 5 ms
10,468 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 383 ms
31,488 KB
testcase_38 AC 369 ms
25,016 KB
testcase_39 AC 315 ms
24,488 KB
testcase_40 AC 325 ms
24,488 KB
testcase_41 AC 287 ms
27,392 KB
testcase_42 WA -
testcase_43 AC 238 ms
21,180 KB
testcase_44 AC 161 ms
22,476 KB
testcase_45 AC 332 ms
31,492 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In member function ‘avl_tree<T>::node* avl_tree<T>::rank(avl_tree<T>::node*, long long int) const [with T = long long int]’:
main.cpp:83:3: warning: control reaches end of non-void function [-Wreturn-type]
   83 |   }
      |   ^

ソースコード

diff #

//変数名Nは人数ではない!!!
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define int long long
using namespace std;

//http://www.prefield.com/algorithm/container/avl_tree.html
template <class T>
struct avl_tree {
  struct node {
    T key;
    int size, height;
    node *child[2];
    node(const T &key) : key(key), size(1), height(1) {
      child[0] = child[1] = 0; }
  } *root;
  typedef node *pointer;
  avl_tree() { root = NULL; }

  pointer find(const T &key) { return find(root, key); }
  node *find(node *t, const T &key) {
    if (t == NULL) return NULL;
    if (key == t->key) return t;
    else if (key < t->key) return find(t->child[0], key);
    else                   return find(t->child[1], key);
  }
  void insert(const T &key) { root = insert(root, new node(key)); }
  node *insert(node *t, node *x) {
    if (t == NULL) return x;
    if (x->key <= t->key) t->child[0] = insert(t->child[0], x);
    else                  t->child[1] = insert(t->child[1], x);
    t->size += 1;
    return balance(t);
  }
  void erase(const T &key) { root = erase(root, key); }
  node *erase(node *t, const T &x) {
    if (t == NULL) return NULL;
    if (x == t->key) {
      return move_down(t->child[0], t->child[1]);
    } else {
      if (x < t->key) t->child[0] = erase(t->child[0], x);
      else            t->child[1] = erase(t->child[1], x);
      t->size -= 1;
      return balance(t);
    }
  }
  node *move_down(node *t, node *rhs) {
    if (t == NULL) return rhs;
    t->child[1] = move_down(t->child[1], rhs);
    return balance(t);
  }
#define sz(t) (t ? t->size : 0)
#define ht(t) (t ? t->height : 0)
  node *rotate(node *t, int l, int r) {
    node *s = t->child[r];
    t->child[r] = s->child[l];
    s->child[l] = balance(t);
    if (t) t->size = sz(t->child[0]) + sz(t->child[1]) + 1;
    if (s) s->size = sz(s->child[0]) + sz(s->child[1]) + 1;
    return balance(s);
  }
  node *balance(node *t) {
    for (int i = 0; i < 2; ++i) {
      if (ht(t->child[!i]) - ht(t->child[i]) < -1) {
        if (ht(t->child[i]->child[!i]) - ht(t->child[i]->child[i]) > 0)
          t->child[i] = rotate(t->child[i], i, !i);
        return rotate(t, !i, i);
      }
    }
    if (t) t->height = max(ht(t->child[0]), ht(t->child[1])) + 1;
    if (t) t->size = sz(t->child[0]) + sz(t->child[1]) + 1;
    return t;
  }
  pointer rank(int k) const { return rank(root, k); }
  pointer rank(node *t, int k) const {
    if (!t) return NULL;
    int m = sz(t->child[0]);
    if (k  < m) return rank(t->child[0], k);
    if (k == m) return t;
    if (k  > m) return rank(t->child[1], k - m - 1);
  }
};

int n;
int level[26];
int t;
string name[100000], prob[100000];
vector<string> nameSorted;


void input() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> level[i];
	cin >> t;
	for (int i = 0; i < t; i++) cin >> name[i] >> prob[i];
	for (int i = 0; i < t; i++) nameSorted.push_back(name[i]);
	sort(nameSorted.begin(), nameSorted.end());
	nameSorted.erase(unique(nameSorted.begin(), nameSorted.end()), nameSorted.end());	//重複削除
}

//nameSortedを使用
int get_id(string name) {
	return lower_bound(nameSorted.begin(), nameSorted.end(), name) - nameSorted.begin();	//出席番号を返す
}

string get_name(int id) {
	return nameSorted[id];
}

int get_score(char prob, int ac_cnt) {
	int lv = level[prob - 'A'];
	return 50 * lv + 50 * lv / (0.8 + 0.2 * (1 + ac_cnt));
}

//集計
avl_tree<long long> bstree;	//-score[i] * t + last[i]を入れると, 高い順位ほど小さな値になるのでうれしい。

void syukei() {
	int i;
	int ac_cnt[26] = {0};
	static int score[100000] = {0};		//score[i] = 出席番号iの人の合計スコア
	static int last_ac[100000] = {0};	//last[i] = 出席番号iの人のラストac
	
	for (i = 0; i < nameSorted.size(); i++) {
		bstree.insert(1145141919893810);
	}
	
	for (i = 0; i < t; i++) {
		int id = get_id(name[i]);
		int prob_id = prob[i][0] - 'A';
		
		if (0 <= prob_id && prob_id < n) {
			if (score[id] == 0) { bstree.erase(1145141919893810); }
			else { bstree.erase(-score[id] * t + last_ac[id]); }
			
			score[id] += get_score(prob[i][0], ac_cnt[prob_id]);
			last_ac[id] = i;
			
			bstree.insert(-score[id] * t + last_ac[id]);
		}
		else {
			int st = 0, ed = nameSorted.size(), mid;	//[st, ed), oooxxx
			while (ed - st >= 2) {
				mid = (st + ed) / 2;
				
				if (bstree.rank(mid)->key > -score[id] * t + last_ac[id]) {
					ed = mid;
				}
				else {
					st = mid;
				}
			}
			cout << st + 1 << endl;
		}
	}
}

signed main() {
	input();
	syukei();
	return 0;
}
0