修复比赛AC助手首AC未显示

This commit is contained in:
Himit_ZH 2021-08-14 23:01:55 +08:00
parent 601efe9c9d
commit 2f5db36427
4 changed files with 50 additions and 13 deletions

View File

@ -35,7 +35,7 @@ int main(int argc, char *args[]){
ouf: 选手输出流
ans: 标准答案流
**/
registerTestlibCmd(argc, argv);
registerTestlibCmd(argc, args);
double pans = ouf.readDouble();
double jans = ans.readDouble();
if (fabs(pans - jans)<0.01)

View File

@ -1,6 +1,5 @@
package top.hcode.hoj.dao;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@ -21,7 +20,7 @@ import java.util.List;
@Mapper
@Repository
public interface ContestRecordMapper extends BaseMapper<ContestRecord> {
List<ContestRecord> getACInfo(IPage iPage, @Param("status") Integer status, @Param("cid") Long cid);
List<ContestRecord> getACInfo(@Param("status") Integer status, @Param("cid") Long cid);
List<ContestRecord> getOIContestRecord(@Param("cid") Long cid, @Param("contestAuthor") String contestAuthor,
@Param("isOpenSealRank") Boolean isOpenSealRank,

View File

@ -4,11 +4,10 @@
<select id="getACInfo" resultType="top.hcode.hoj.pojo.entity.ContestRecord">
SELECT c.id,c.uid,c.username,c.display_id,c.cid,c.realname,c.pid,c.time,c.status,c.checked,c.submit_id,
c.submit_time,c.first_blood FROM contest_record c,
c.submit_time FROM contest_record c,
(SELECT status,uid,pid,cpid,
MIN(submit_id) AS min_submit_id,
MIN(submit_time) AS min_submit_time,
MAX(first_blood) AS max_first_blood
MIN(submit_time) AS min_submit_time
FROM contest_record GROUP BY status,uid,pid,cpid
) AS t
<where>
@ -16,7 +15,6 @@
AND t.cpid=c.cpid
AND t.min_submit_id=c.submit_id
AND t.min_submit_time=c.submit_time
AND t.max_first_blood=c.first_blood
<if test="status!=null">
AND c.status=#{status}
</if>

View File

@ -39,8 +39,52 @@ public class ContestRecordServiceImpl extends ServiceImpl<ContestRecordMapper, C
@Override
public IPage<ContestRecord> getACInfo(Integer currentPage, Integer limit, Integer status, Long cid) {
List<ContestRecord> acInfo = contestRecordMapper.getACInfo(status, cid);
HashMap<Long, Integer> pidMapIndex = new HashMap<>(20);
HashMap<Integer, Long> indexMapTime = new HashMap<>(20);
for (int i = 0; i < acInfo.size(); i++) {
ContestRecord contestRecord = acInfo.get(i);
contestRecord.setFirstBlood(false);
Integer index = pidMapIndex.get(contestRecord.getPid());
if (index == null) {
pidMapIndex.put(contestRecord.getPid(), i);
indexMapTime.put(i, contestRecord.getTime());
} else {
Long firstTime = indexMapTime.get(index);
Long tmpTime = contestRecord.getTime();
if (tmpTime < firstTime) {
pidMapIndex.put(contestRecord.getPid(), i);
indexMapTime.put(i, tmpTime);
}
}
}
List<ContestRecord> pageList = new ArrayList<>();
int count = acInfo.size();
//计算当前页第一条数据的下标
int currId = currentPage > 1 ? (currentPage - 1) * limit : 0;
for (int i = 0; i < limit && i < count - currId; i++) {
ContestRecord contestRecord = acInfo.get(currId + i);
if (pidMapIndex.get(contestRecord.getPid()) == currId + i){
contestRecord.setFirstBlood(true);
}
pageList.add(contestRecord);
}
Page<ContestRecord> page = new Page<>(currentPage, limit);
return page.setRecords(contestRecordMapper.getACInfo(page, status, cid));
page.setSize(limit);
page.setCurrent(currentPage);
page.setTotal(count);
page.setRecords(pageList);
return page;
}
@Override
@ -66,8 +110,6 @@ public class ContestRecordServiceImpl extends ServiceImpl<ContestRecordMapper, C
page.setSize(limit);
page.setCurrent(currentPage);
page.setTotal(count);
//计算分页总页数
page.setPages(count % 10 == 0 ? count / 10 : count / 10 + 1);
page.setRecords(pageList);
return page;
@ -95,8 +137,6 @@ public class ContestRecordServiceImpl extends ServiceImpl<ContestRecordMapper, C
page.setSize(limit);
page.setCurrent(currentPage);
page.setTotal(count);
//计算分页总页数
page.setPages(count % 10 == 0 ? count / 10 : count / 10 + 1);
page.setRecords(pageList);
return page;
@ -286,7 +326,7 @@ public class ContestRecordServiceImpl extends ServiceImpl<ContestRecordMapper, C
// 根据总得分进行降序,再根据总时耗升序排序
List<OIContestRankVo> orderResultList = result.stream()
.sorted(Comparator.comparing(OIContestRankVo::getTotalScore, Comparator.reverseOrder())
.thenComparing(OIContestRankVo::getTotalTime,Comparator.naturalOrder()))
.thenComparing(OIContestRankVo::getTotalTime, Comparator.naturalOrder()))
.collect(Collectors.toList());
return orderResultList;
}