WA 90pts QAQ
查看原帖
WA 90pts QAQ
1023961
Ryzen_9_9950X3D楼主2023/10/5 10:38

本蒟蒻代码如下:

#include <bits/stdc++.h>
using namespace std;
#define int long long
int colliders[30000005],ct = 0;
int a,b;
int chck(int x)
{
    if(x < 2)
    {
        return 1;
    }
    if(colliders[x])
    {
        return 0;
    }
    for(int j = x + x;j <= a;j += x)
    {
        if(colliders[j] == 1)
        {
            ct = j;
            return -1;
        }
    }
    for(int i = 2;i * i <= x;i++)
    {
        if(x % i == 0)
        {
            for(int j = 0;j <= a;j += i)
            {
                if(colliders[j] == 1)
                {
                    ct = j;
                    return -1;
                }
            }
            for(int j = 0;j <= a;j += x / i)
            {
                if(colliders[j] == 1)
                {
                    ct = j;
                    return -1;
                }
            }
        }
    }
    return 1;
}
signed main()
{
    cin >> a >> b;
    for(int i = 1;i <= b;i++)
    {
        char c;
        int d;
        cin >> c >> d;
        if(c == '+')
        {
            int e = chck(d);
            if(e == 1)
            {
                colliders[d] = 1;
                cout << "Success" << endl;
            }
            if(e == 0)
            {
                cout << "Already on" << endl;
            }
            if(e == -1)
            {
                cout << "Conflict with " << ct << endl;
            }
        }
        else
        {
            if(colliders[d] == 0)
            {
                cout << "Already off" << endl;
            }
            else
            {
                colliders[d] = 0;
                cout << "Success" << endl;
            }
        }
    }
    return 0;
}
2023/10/5 10:38
加载中...