题解:P10844 [EGOI2024] Infinite Race / 无限赛跑

题解:P10844 [EGOI2024] Infinite Race / 无限赛跑

有 n 个人在环形跑道上跑步,和 q 次超越别人或被别人超越, 别人要么在Anika前面,要么在后面

怎么说呢,建议降红

由于只有重复超过一个人才肯定是跑过一圈的,所以一个数组就行了,每超过一次就打上标记,不然去掉标记。

#include <bits/stdc++.h>
using namespace std;
int n, q, x, f[200010], ans = 1;
int main(){
    cin >> n >> q;
    while(q--){
        cin >> x;
        if(x > 0){
            if(f[x] == ans) f[x] = ++ans;
            else f[x] = ans;
        } else x = abs(x), f[x] = 0;
    }
    cout << ans - 1;
    return 0;
}

不要脸

点个赞吧

posted @ 2024-08-19 14:27  wayneoi  阅读(2)  评论(0编辑  收藏  举报