diff --git a/src/main.cpp b/src/main.cpp index 4af4dd1..899225e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -100,13 +100,12 @@ template inline void write( #endif // clang-format on // end of fast-read libarary -#include -#include - #include #include #include #include +#include +#include #include #include #include @@ -179,6 +178,7 @@ struct RawTeamDataType { int rank; int name_rank; std::multiset> pass_time_before_freeze; + std::multiset> pass_time_before_freeze_new; int query_status_index[4], query_problem_index[26], query_problem_status_index[26][4]; // as index in submissions are 0 based, so we use -1 to indicate that the team @@ -230,8 +230,10 @@ inline bool operator<(const ScoreBoredElementType &a, } return team_data[a.tid].name_rank < team_data[b.tid].name_rank; } -// std::set score_board; -__gnu_pbds::tree,__gnu_pbds::rb_tree_tag> score_board; +std::set score_board; +// __gnu_pbds::tree, __gnu_pbds::rb_tree_tag> +// score_board; std::vector teams_to_be_updated; std::vector teams_not_latest; std::vector value_in_score_board; @@ -285,7 +287,9 @@ void StartCompetition(int duration_time, int problem_count) { value_in_score_board.resize(team_number + 1); for (int i = 1; i <= team_number; i++) { score_board.insert(ScoreBoredElementType(i, 0, 0)); - value_in_score_board[i]=ScoreBoredElementType(i, 0, 0); + value_in_score_board[i] = ScoreBoredElementType(i, 0, 0); + if (score_board.find(value_in_score_board[i]) == score_board.end()) + throw "cannot find tid in score_board immediately after insert in func StartCompetition"; } int cnt = 0; for (auto it = score_board.begin(); it != score_board.end(); ++it) { @@ -317,13 +321,13 @@ inline void Submit(char problem_name, char *team_name, if (team_data[team_id].already_passed[problem_name - 'A'] == false) { team_data[team_id].first_pass_time[problem_name - 'A'] = time; if (competition_status == kNormalRunning) - team_data[team_id].pass_time_before_freeze.insert(time); + team_data[team_id].pass_time_before_freeze_new.insert(time); } team_data[team_id].already_passed[problem_name - 'A'] = true; if (competition_status == kNormalRunning) { team_data[team_id].already_passed_before_block[problem_name - 'A'] = true; - if(teams_not_latest[team_id]==false) + if (teams_not_latest[team_id] == false) teams_to_be_updated.push_back(team_id); teams_not_latest[team_id] = true; } @@ -359,9 +363,8 @@ void FlushScoreBoard(bool show_info = true, bool rebuild = true) { // score_board.insert(ScoreBoredElementType(i, score, penalty)); // value_in_score_board[i]=ScoreBoredElementType(i, score, penalty); // } - for(int i=0;itid].already_passed[i]) { int score = it->score + 1; - team_data[it->tid].pass_time_before_freeze.insert( + team_data[it->tid].pass_time_before_freeze_new.insert( team_data[it->tid].first_pass_time[i]); - if(teams_not_latest[it->tid]==false) + if (teams_not_latest[it->tid] == false) teams_to_be_updated.push_back(it->tid); teams_not_latest[it->tid] = true; int penalty = it->penalty + team_data[it->tid].first_pass_time[i] + 20 * team_data[it->tid].try_times_before_pass[i]; int tid = it->tid; score_board.erase(it); + team_data[it->tid].pass_time_before_freeze=team_data[it->tid].pass_time_before_freeze_new; score_board.insert(ScoreBoredElementType(tid, score, penalty)); - value_in_score_board[tid]=ScoreBoredElementType(tid, score, penalty); + value_in_score_board[tid] = + ScoreBoredElementType(tid, score, penalty); + if (score_board.find(value_in_score_board[tid]) == score_board.end()) + throw "cannot find tid in score_board immediately after insert in func ScrollScoreBoard"; if (!is_first && ScoreBoredElementType(tid, score, penalty) < nval) { auto newp = score_board.find(ScoreBoredElementType(tid, score, penalty)); @@ -558,6 +579,28 @@ void QuerySubmission(char *team_name, char *problem_name, char *submit_status) { write(team_name, ' ', res.problem_name, ' ', StatusType2Text[res.status].c_str(), ' ', res.submit_time, "\n"); } +void PrintStatus() { + for(int i=1;i<=team_number;i++) + { + fprintf(stderr,"team %d: %s\n",i,team_data[i].name.c_str()); + /*value_in_score_board*/ + fprintf(stderr,"value_in_score_board: %d %d %d\n",value_in_score_board[i].tid,value_in_score_board[i].score,value_in_score_board[i].penalty); + } + /*score_board*/ + fprintf(stderr,"score_board:\n"); + for(auto it=score_board.begin();it!=score_board.end();++it) + { + fprintf(stderr,"%d %d %d\n",it->tid,it->score,it->penalty); + } + } +void CheckAccordanceBetweenScoreBoardAndValueInScoreBoard() { + for (int i = 1; i <= team_number; i++) { + if (score_board.find(value_in_score_board[i]) == score_board.end()) { + PrintStatus(); + throw "cannot find tid in score_board immediately after insert in func CheckAccordanceBetweenScoreBoardAndValueInScoreBoard"; + } + } +} } // namespace BackEnd /** @@ -710,12 +753,14 @@ inline void Excute(const char *const command) { throw "Unknown command."; } } + if (BackEnd::competition_status != BackEnd::kNotStarted) + BackEnd::CheckAccordanceBetweenScoreBoardAndValueInScoreBoard(); } } // namespace API } // namespace ICPCManager int main() { - // freopen("tmp/pro.in","r",stdin); - // freopen("tmp/pro.out","w",stdout); + // freopen("tmp/pro.in", "r", stdin); + // freopen("tmp/pro.out", "w", stdout); ICPCManager::BackEnd::team_data.reserve(10005); char command[1024]; try {