結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー antaanta
提出日時 2016-11-18 06:11:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 5,000 ms
コード長 2,534 bytes
コンパイル時間 2,222 ms
コンパイル使用メモリ 183,584 KB
実行使用メモリ 16,520 KB
最終ジャッジ日時 2023-10-22 08:22:28
合計ジャッジ時間 7,533 ms
ジャッジサーバーID
(参考情報)
judge14 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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 3 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 47 ms
4,436 KB
testcase_13 AC 75 ms
7,604 KB
testcase_14 AC 83 ms
7,604 KB
testcase_15 AC 75 ms
7,604 KB
testcase_16 AC 89 ms
7,604 KB
testcase_17 AC 79 ms
7,604 KB
testcase_18 AC 46 ms
4,436 KB
testcase_19 AC 78 ms
7,604 KB
testcase_20 AC 78 ms
7,604 KB
testcase_21 AC 76 ms
7,604 KB
testcase_22 AC 77 ms
7,604 KB
testcase_23 AC 46 ms
4,436 KB
testcase_24 AC 77 ms
7,604 KB
testcase_25 AC 50 ms
4,436 KB
testcase_26 AC 49 ms
4,436 KB
testcase_27 AC 72 ms
7,604 KB
testcase_28 AC 74 ms
7,604 KB
testcase_29 AC 76 ms
7,604 KB
testcase_30 AC 71 ms
7,604 KB
testcase_31 AC 73 ms
7,604 KB
testcase_32 AC 77 ms
7,604 KB
testcase_33 AC 76 ms
7,604 KB
testcase_34 AC 48 ms
4,436 KB
testcase_35 AC 71 ms
7,604 KB
testcase_36 AC 49 ms
4,436 KB
testcase_37 AC 136 ms
16,520 KB
testcase_38 AC 123 ms
10,184 KB
testcase_39 AC 73 ms
10,184 KB
testcase_40 AC 108 ms
10,184 KB
testcase_41 AC 98 ms
10,416 KB
testcase_42 AC 96 ms
10,416 KB
testcase_43 AC 43 ms
4,436 KB
testcase_44 AC 36 ms
4,436 KB
testcase_45 AC 67 ms
16,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
//Ω(同じスコアの人たち)かけるがビット並列バージョン
//おそらくAC

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

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;
	}
};

struct BitVector {
	std::vector<uint64_t> bits;
	int length;

	BitVector() : length(0) {}

	int size() const { return length; }

	void append1() {
		if((length ++ & 63) == 0)
			bits.push_back(1);
		else
			bits.back() |= uint64_t(1) << ((length - 1) & 63);
	}

	void reset(int i) {
		bits[i >> 6] &= ~(uint64_t(1) << (i & 63));
	}

	int sum(int i) const {
		int res = 0;
		int blocks = i >> 6;
		if(i & 63)
			res += popcount(bits[blocks] << (-i & 63));
		for(int k = blocks - 1; k >= 0; -- k)
			res += popcount(bits[k]);
		return res;
	}

	static int popcount(uint64_t x) {
#ifdef __GNUC__
		return __builtin_popcountll(x);
#else
		return (int)_mm_popcnt_u64(x);
#endif
	}
};

int main() {
	int N;
	scanf("%d", &N);
	vector<int> L(N);
	for(int i = 0; i < N; ++ i)
		scanf("%d", &L[i]);
	int T;
	scanf("%d", &T);

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

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

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

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

	for(int i = 0; i < T; ++ i) {
		char name[17], P[2];
		scanf("%s%s", name, P);
		if(*P != '?') {
			int p = *P - 'A';

			int stars = L[p];
			int rank = ++ count[p];
			int score = 50 * stars + 50 * stars * 10 / (8 + 2 * rank);

			auto &c = contestants[name];

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

			c.totalScore += score;
			c.lastTime = i + 1;

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

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

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