結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー antaanta
提出日時 2016-11-18 05:47:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 5,000 ms
コード長 3,525 bytes
コンパイル時間 2,522 ms
コンパイル使用メモリ 182,424 KB
実行使用メモリ 16,600 KB
最終ジャッジ日時 2023-10-22 08:22:36
合計ジャッジ時間 6,570 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 47 ms
4,700 KB
testcase_13 AC 70 ms
7,924 KB
testcase_14 AC 70 ms
7,760 KB
testcase_15 AC 68 ms
7,976 KB
testcase_16 AC 69 ms
7,868 KB
testcase_17 AC 71 ms
7,868 KB
testcase_18 AC 48 ms
4,700 KB
testcase_19 AC 70 ms
7,768 KB
testcase_20 AC 70 ms
7,732 KB
testcase_21 AC 70 ms
7,884 KB
testcase_22 AC 73 ms
7,916 KB
testcase_23 AC 47 ms
4,700 KB
testcase_24 AC 72 ms
7,868 KB
testcase_25 AC 46 ms
4,496 KB
testcase_26 AC 47 ms
4,436 KB
testcase_27 AC 73 ms
7,884 KB
testcase_28 AC 74 ms
7,888 KB
testcase_29 AC 73 ms
7,756 KB
testcase_30 AC 73 ms
7,976 KB
testcase_31 AC 74 ms
7,908 KB
testcase_32 AC 73 ms
7,740 KB
testcase_33 AC 73 ms
7,868 KB
testcase_34 AC 47 ms
4,520 KB
testcase_35 AC 69 ms
7,972 KB
testcase_36 AC 47 ms
4,524 KB
testcase_37 AC 115 ms
16,600 KB
testcase_38 AC 90 ms
10,276 KB
testcase_39 AC 67 ms
10,276 KB
testcase_40 AC 69 ms
10,276 KB
testcase_41 AC 87 ms
10,604 KB
testcase_42 AC 91 ms
10,604 KB
testcase_43 AC 40 ms
4,476 KB
testcase_44 AC 34 ms
4,824 KB
testcase_45 AC 63 ms
16,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#ifdef NDEBUG
#error assert is disabled!
#endif

template<typename T>
T readNatural(T lo, T up) {
	assert(0 <= lo && lo <= up);
	T x = 0;
	while(1) {
		int d = getchar();
		if(!('0' <= d && d <= '9')) {
			ungetc(d, stdin);
			break;
		}
		d -= '0';
		assert(d <= up && x <= (up - d) / 10);
		x = x * 10 + d;
	}
	assert(lo <= x && x <= up);
	return x;
}

void readSpace() { int c = getchar(); assert(c == ' '); }
static bool read_eof = false;
void readEOL() {
	int c = getchar();
	if(c == EOF) {
		assert(!read_eof);
		read_eof = true;
	} else {
		assert(c == '\n');
	}
}
void readEOF() {
	assert(!read_eof);
	int c = getchar();
	assert(c == EOF);
	read_eof = true;
}


int readString(char *buf, int minLen, int maxLen, bool charactors[128]) {
	assert(0 <= minLen && minLen <= maxLen);
	int len = 0;
	while(1) {
		int c = getchar();
		if(!(0 <= c && c < 128) || !charactors[c]) {
			ungetc(c, stdin);
			break;
		}
		assert(len < maxLen);
		buf[len ++] = c;
	}
	assert(minLen <= len && len <= maxLen);
	buf[len] = 0;
	return len;
}

struct FenwickTree {
	typedef int T;
	vector<T> v;

	void init(int n) { v.assign(n, T()); }

	int size() const { return (int)v.size(); }

	void add(int i, T x) {
		for(; i < size(); i |= i + 1) v[i] += x;
	}

	T sum(int i) const {
		T r = T();
		for(-- i; i >= 0; i = (i & (i + 1)) - 1) r += v[i];
		return r;
	}

	T sum(int left, int right) const {	//[left, right)
		return sum(right) - sum(left);
	}

	void push_back(T x) {
		int i = size();
		for(int w = 1; i & w; w <<= 1)
			x += v[i - w];
		v.push_back(x);
	}
};

int main() {
	bool lowercases[128] = {}, uppercaseOrQM[128] = {};
	for(int a = 0; a < 26; ++ a) {
		lowercases['a' + a] = true;
		uppercaseOrQM['A' + a] = true;
	}
	uppercaseOrQM['?'] = true;

	int N = readNatural(1, 26);
	readEOL();
	vector<int> L(N);
	for(int i = 0; i < N; ++ i) {
		if(i != 0) readSpace();
		L[i] = readNatural(1, 6);
	}
	readEOL();
	int T = readNatural(1, 100000);
	readEOL();

	struct Contestant {
		int totalScore;
		int lastTime;
		uint32_t acceptedMask;
		int subIndex;

		Contestant() :
			totalScore(0), lastTime(0),
			acceptedMask(0),
			subIndex(-1) {}
	};

	std::map<std::string, Contestant> contestants;
	std::vector<int> count(N, 0);
	int M = 0;

	const int MaxScore = 15600;
	FenwickTree mainFT;
	mainFT.init(MaxScore + 1);
	vector<FenwickTree> subFTs(MaxScore + 1);
	std::vector<int> scoreCount(MaxScore + 1);

	for(int i = 0; i < T; ++ i) {
		char name[17], P[2];
		readString(name, 1, 16, lowercases);
		readSpace();
		readString(P, 1, 1, uppercaseOrQM);
		readEOL();
		if(*P != '?') {
			int p = *P - 'A';
			assert(0 <= p && p < N);
			int stars = L[p];
			int rank = ++ count[p];
			int score = 50 * stars + 50 * stars * 10 / (8 + 2 * rank);
			assert(score > 0);
			auto &c = contestants[name];

			if(c.totalScore != 0) {
				mainFT.add(c.totalScore, -1);
				subFTs[c.totalScore].add(c.subIndex, -1);
			}

			c.totalScore += score;
			c.lastTime = i + 1;
			assert((c.acceptedMask >> p & 1) == 0);
			c.acceptedMask |= uint32_t(1) << p;

			assert(c.totalScore <= MaxScore);
			mainFT.add(c.totalScore, 1);
			c.subIndex = subFTs[c.totalScore].size();
			subFTs[c.totalScore].push_back(1);
		} else {
			auto &c = contestants[name];
			assert(c.totalScore != 0);

			int ans = 0;
			ans += (int)contestants.size() - mainFT.sum(c.totalScore + 1);
			ans += subFTs[c.totalScore].sum(c.subIndex);

			printf("%d\n", ans + 1);

			++ M;
		}
	}
	assert(M > 0);
	readEOF();
	return 0;
}
0