結果
問題 |
No.449 ゆきこーだーの雨と雪 (4)
|
ユーザー |
![]() |
提出日時 | 2016-11-18 06:15:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,250 ms / 5,000 ms |
コード長 | 1,809 bytes |
コンパイル時間 | 1,971 ms |
コンパイル使用メモリ | 182,036 KB |
実行使用メモリ | 15,320 KB |
最終ジャッジ日時 | 2024-09-22 09:26:08 |
合計ジャッジ時間 | 9,198 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
#include "bits/stdc++.h" using namespace std; //Ω(同じスコアの人たち)かける手抜きバージョン 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; } }; 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; Contestant() : totalScore(0), lastTime(0) {} }; std::map<std::string, Contestant> contestants; std::vector<int> count(N, 0); const int MaxScore = 15600; FenwickTree mainFT; mainFT.init(MaxScore + 1); vector<std::vector<int>> lists(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); auto &v = lists[c.totalScore]; v.erase(find(v.begin(), v.end(), c.lastTime)); } c.totalScore += score; c.lastTime = i + 1; assert(c.totalScore <= MaxScore); mainFT.add(c.totalScore, 1); auto &v = lists[c.totalScore]; v.push_back(c.lastTime); } else { auto &c = contestants[name]; int ans = 0; ans += (int)contestants.size() - mainFT.sum(c.totalScore + 1); const auto &v = lists[c.totalScore]; ans += (int)(find(v.begin(), v.end(), c.lastTime) - v.begin()); printf("%d\n", ans + 1); } } return 0; }