比赛正在进行中

很遗憾,您尚未报名。比赛结束后再来看吧~

"); } } } if (isset($_POST['check_notice'])) { $result = DB::query("select * from contests_notice where contest_id = '${contest['id']}' order by time desc limit 1"); try { while ($row = DB::fetch($result)) { if (new DateTime($row['time']) > new DateTime($_POST['last_time'])) { die(json_encode(array('msg' => $row['title'] . ' : ' . $row['content'], 'time' => UOJTime::$time_now_str))); } } } catch (Exception $e) { } die(json_encode(array('time' => UOJTime::$time_now_str))); } if (isset($_GET['tab'])) { $cur_tab = $_GET['tab']; } else { $cur_tab = 'dashboard'; } // problems: pos => id // data : id, submit_time, submitter, problem_pos, score // people : username, user_rating function queryContestData() { global $contest; $problems = array(); $prob_pos = array(); $n_problems = 0; $result = DB::query("select problem_id from contests_problems where contest_id = ${contest['id']} order by problem_id"); while ($row = DB::fetch($result, MYSQLI_NUM)) { $prob_pos[$problems[] = (int)$row[0]] = $n_problems++; } $data = array(); if ($contest['cur_progress'] < CONTEST_FINISHED) { $result = DB::query("select id, submit_time, submitter, problem_id, score from submissions where contest_id = {$contest['id']} and score is not null order by id"); } else { $result = DB::query("select submission_id, date_add('{$contest['start_time_str']}', interval penalty second), submitter, problem_id, score from contests_submissions where contest_id = {$contest['id']}"); } while ($row = DB::fetch($result, MYSQLI_NUM)) { $row[0] = (int)$row[0]; $row[3] = $prob_pos[$row[3]]; $row[4] = (int)$row[4]; $data[] = $row; } $people = array(); $result = DB::query("select username, user_rating from contests_registrants where contest_id = {$contest['id']} and has_participated = 1"); while ($row = DB::fetch($result, MYSQLI_NUM)) { $row[1] = (int)$row[1]; $people[] = $row; } return array('problems' => $problems, 'data' => $data, 'people' => $people); } function calcStandings($contest_data, &$score, &$standings, $update_contests_submissions = false) { global $contest; // score: username, problem_pos => score, penalty, id $score = array(); $n_people = count($contest_data['people']); $n_problems = count($contest_data['problems']); foreach ($contest_data['people'] as $person) { $score[$person[0]] = array(); } foreach ($contest_data['data'] as $submission) { $penalty = (new DateTime($submission[1]))->getTimestamp() - $contest['start_time']->getTimestamp(); if ($contest['extra_config']['standings_version'] >= 2) { if ($submission[4] == 0) { $penalty = 0; } } $score[$submission[2]][$submission[3]] = array($submission[4], $penalty, $submission[0]); } // standings: rank => score, penalty, [username, user_rating], virtual_rank $standings = array(); foreach ($contest_data['people'] as $person) { $cur = array(0, 0, $person); for ($i = 0; $i < $n_problems; $i++) { if (isset($score[$person[0]][$i])) { $cur_row = $score[$person[0]][$i]; $cur[0] += $cur_row[0]; $cur[1] += $cur_row[1]; if ($update_contests_submissions) { DB::insert("insert into contests_submissions (contest_id, submitter, problem_id, submission_id, score, penalty) values ({$contest['id']}, '{$person[0]}', {$contest_data['problems'][$i]}, {$cur_row[2]}, {$cur_row[0]}, {$cur_row[1]})"); } } } $standings[] = $cur; } usort($standings, function($lhs, $rhs) { if ($lhs[0] != $rhs[0]) { return $rhs[0] - $lhs[0]; } else if ($lhs[1] != $rhs[1]) { return $lhs[1] - $rhs[1]; } else { return strcmp($lhs[2][0], $rhs[2][0]); } }); $is_same_rank = function($lhs, $rhs) { return $lhs[0] == $rhs[0] && $lhs[1] == $rhs[1]; }; for ($i = 0; $i < $n_people; $i++) { if ($i == 0 || !$is_same_rank($standings[$i - 1], $standings[$i])) { $standings[$i][] = $i + 1; } else { $standings[$i][] = $standings[$i - 1][3]; } } } if (isSuperUser($myUser)) { if (CONTEST_PENDING_FINAL_TEST <= $contest['cur_progress'] && $contest['cur_progress'] <= CONTEST_TESTING) { $start_test_form = new UOJForm('start_test'); $start_test_form->handle = function() { global $contest; $result = DB::query("select id, problem_id, content from submissions where contest_id = {$contest['id']}"); while ($submission = DB::fetch($result, MYSQLI_ASSOC)) { if (!isset($contest['extra_config']["problem_{$submission['problem_id']}"])) { $content = json_decode($submission['content'], true); if (isset($content['final_test_config'])) { $content['config'] = $content['final_test_config']; unset($content['final_test_config']); } if (isset($content['first_test_config'])) { unset($content['first_test_config']); } $esc_content = DB::escape(json_encode($content)); DB::update("update submissions set judge_time = NULL, result = '', score = NULL, status = 'Waiting Rejudge', content = '$esc_content' where id = {$submission['id']}"); } } DB::query("update contests set status = 'testing' where id = {$contest['id']}"); }; $start_test_form->submit_button_config['class_str'] = 'btn btn-danger btn-block'; $start_test_form->submit_button_config['smart_confirm'] = ''; if ($contest['cur_progress'] < CONTEST_TESTING) { $start_test_form->submit_button_config['text'] = '开始最终测试'; } else { $start_test_form->submit_button_config['text'] = '重新开始最终测试'; } $start_test_form->runAtServer(); } if ($contest['cur_progress'] >= CONTEST_TESTING) { $publish_result_form = new UOJForm('publish_result'); $publish_result_form->handle = function() { // time config set_time_limit(0); ignore_user_abort(true); global $contest; $contest_data = queryContestData(); calcStandings($contest_data, $score, $standings, true); if (!isset($contest['extra_config']['unrated'])) { $rating_k = isset($contest['extra_config']['rating_k']) ? $contest['extra_config']['rating_k'] : 400; $ratings = calcRating($standings, $rating_k); } else { $ratings = array(); for ($i = 0; $i < count($standings); $i++) { $ratings[$i] = $standings[$i][2][1]; } } for ($i = 0; $i < count($standings); $i++) { $user = queryUser($standings[$i][2][0]); $change = $ratings[$i] - $user['rating']; $user_link = getUserLink($user['username']); if ($change != 0) { $tail = '' . ($change > 0 ? '+' : '') . $change . ''; $content = <<${user_link} 您好:

您在 {$contest['name']} 这场比赛后的Rating变化为${tail},当前Rating为 {$ratings[$i]}

EOD; } else { $content = <<${user_link} 您好:

您在 {$contest['name']} 这场比赛后Rating没有变化。当前Rating为 {$ratings[$i]}

EOD; } sendSystemMsg($user['username'], 'Rating变化通知', $content); DB::query("update user_info set rating = {$ratings[$i]} where username = '{$standings[$i][2][0]}'"); DB::query("update contests_registrants set rank = {$standings[$i][3]} where contest_id = {$contest['id']} and username = '{$standings[$i][2][0]}'"); } DB::query("update contests set status = 'finished' where id = {$contest['id']}"); }; $publish_result_form->submit_button_config['class_str'] = 'btn btn-danger btn-block'; $publish_result_form->submit_button_config['smart_confirm'] = ''; $publish_result_form->submit_button_config['text'] = '公布成绩'; $publish_result_form->runAtServer(); } } function echoDashboard() { global $myUser, $contest, $post_notice; echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $contest_problems = DB::selectAll("select contests_problems.problem_id, best_ac_submissions.submission_id from contests_problems left join best_ac_submissions on contests_problems.problem_id = best_ac_submissions.problem_id and submitter = '{$myUser['username']}' where contest_id = {$contest['id']} order by contests_problems.problem_id asc"); for ($i = 0; $i < count($contest_problems); $i++) { $problem = queryProblemBrief($contest_problems[$i]['problem_id']); echo ''; if ($contest_problems[$i]['submission_id']) { echo ''; echo ''; echo ''; } echo ''; echo '
#', UOJLocale::get('problems::problem'), '
'; } else { echo ''; } echo chr(ord('A') + $i), '', getContestProblemLink($problem, $contest['id']), '
'; echo '
'; echo '

', UOJLocale::get('contests::contest notice'), '

'; $header = ''; $header .= ''; $header .= ''.UOJLocale::get('title').''; $header .= ''.UOJLocale::get('content').''; $header .= ''.UOJLocale::get('time').''; $header .= ''; echoLongTable(array('*'), 'contests_notice', "contest_id = '{$contest['id']}'", "order by time desc", $header, function($notice) { echo ''; echo '', HTML::escape($notice['title']), ''; echo '', $notice['content'], ''; echo '', $notice['time'], ''; echo ''; }, array( 'table_classes' => array('table', 'table-bordered', 'table-hover', 'table-striped', 'table-vertical-middle', 'table-text-center'), 'echo_full' => true ) ); if (isSuperUser(Auth::user())) { echo '
'; echo ''; echo '
'; echo ''; echo << $(document).ready(function() { $('#button-display-post-notice').click(function() { $('#div-form-post-notice').toggle('fast'); }); }); EOD; } } function echoMySubmissions() { global $contest, $myUser; $show_all_submissions_status = Cookie::get('show_all_submissions') !== null ? 'checked="checked" ' : ''; $show_all_submissions = UOJLocale::get('contests::show all submissions'); echo << EOD; if (Cookie::get('show_all_submissions') !== null) { echoSubmissionsList("contest_id = {$contest['id']}", 'order by id desc', array('judge_time_hidden' => ''), $myUser); } else { echoSubmissionsList("submitter = '{$myUser['username']}' and contest_id = {$contest['id']}", 'order by id desc', array('judge_time_hidden' => ''), $myUser); } } function echoStandings() { global $contest; $contest_data = queryContestData(); calcStandings($contest_data, $score, $standings); echo '
'; echo '
'; /* echo '
'; echo ''; echo '
'; echo '
'; */ echo ''; } function echoContestCountdown() { global $contest; $rest_second = $contest['end_time']->getTimestamp() - UOJTime::$time_now->getTimestamp(); $time_str = UOJTime::$time_now_str; $contest_ends_in = UOJLocale::get('contests::contest ends in'); echo <<

$contest_ends_in

EOD; } function echoContestJudgeProgress() { global $contest; if ($contest['cur_progress'] < CONTEST_TESTING) { $rop = 0; $title = UOJLocale::get('contests::contest pending final test'); } else { $total = DB::selectCount("select count(*) from submissions where contest_id = {$contest['id']}"); $n_judged = DB::selectCount("select count(*) from submissions where contest_id = {$contest['id']} and status = 'Judged'"); $rop = $total == 0 ? 100 : (int)($n_judged / $total * 100); $title = UOJLocale::get('contests::contest final testing'); } echo <<

$title

{$rop}%
EOD; } function echoContestFinished() { $title = UOJLocale::get('contests::contest ended'); echo <<

$title

EOD; } $post_notice = new UOJForm('post_notice'); $post_notice->addInput('title', 'text', '标题', '', function($title) { if (!$title) { return '标题不能为空'; } return ''; }, null ); $post_notice->addTextArea('content', '正文', '', function($content) { if (!$content) { return '公告不能为空'; } return ''; }, null ); $post_notice->handle = function() { global $contest; $title = DB::escape($_POST['title']); $content = DB::escape($_POST['content']); DB::query("insert into contests_notice (contest_id, title, content, time) values ('{$contest['id']}', '$title', '$content', now())"); }; $post_notice->runAtServer(); $tabs_info = array( 'dashboard' => array( 'name' => UOJLocale::get('contests::contest dashboard'), 'url' => "/contest/{$contest['id']}" ), 'submissions' => array( 'name' => UOJLocale::get('contests::contest submissions'), 'url' => "/contest/{$contest['id']}/submissions" ), 'standings' => array( 'name' => UOJLocale::get('contests::contest standings'), 'url' => "/contest/{$contest['id']}/standings" ) ); if (!isset($tabs_info[$cur_tab])) { become404Page(); } $page_header = HTML::stripTags($contest['name']) . ' - '; ?>


此次比赛为OI赛制。

注意:比赛时只显示测样例的结果。

管理
printHTML(); ?>
printHTML(); ?>

比赛资料