답안 #555232

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
555232 2022-04-30T09:52:05 Z BT21tata Radio (COCI22_radio) C++17
30 / 110
408 ms 60936 KB
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define SPEED ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define rall(v) (v).rbegin(),(v).rend()
#define all(v) (v).begin(),(v).end()
#define setp fixed<<setprecision
#define OK cerr<<"OK"<<endl<<flush
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define F first
#define S second
#define y0 jahdakdh
#define y1 jahsadakdakdh
#define endl '\n'
const ll MOD=1e9+7;
const ll mod=(1ll<<31)-1;
const ld eps=1e-8;
using namespace std;
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());

bool a[1000005];
vector<int>primes[1000005];
int cnt, pr[1000005], n, Q;

void solve()
{
    for(ll i=2; i<=1000000; i++)
    {
        if(pr[i]==0)
        {
            for(ll j=i; j<=1000000; j+=i)
            {
                primes[j].pb(i);
                pr[j]=1;
            }
        }
    }

    memset(pr, 0, sizeof(pr));
    while(Q--)
    {
        char q;
        int x;
        cin>>q>>x;
        if(q=='S')
        {
            if(a[x]==0)
            {
                a[x]=1;
                for(int u : primes[x])
                {
                    pr[u]++;
                    //cout<<u<<' '<<x<<' '<<pr[u]<<endl;
                    if(pr[u]==2) cnt++;
                }
            }
            else
            {
                a[x]=0;
                for(int u : primes[x])
                {
                    pr[u]--;
                    if(pr[u]==1) cnt--;
                }
            }
        }
        else
        {
            cin>>x;
            if(cnt) cout<<"DA\n";
            else cout<<"NE\n";
        }
    }   
}

void solve100()
{
    while(Q--)
    {
        char q;
        cin>>q;
        if(q=='S')
        {
            int x; cin>>x;
            a[x]=!a[x];
        }
        else
        {
            bool f=1;
            int l, r;
            cin>>l>>r;
 
            for(int i=l; i<=r; i++)
            {
                for(int j=i+1; j<=r; j++)
                {
                    if(a[i] and a[j] and __gcd(i, j)!=1)
                    {
                        //cout<<i<<' '<<j<<endl;
                        f=0;
                    }
                }
            }
            cout<<(f? "NE\n":"DA\n");
        }
    }

}

int main()
{
    SPEED;
    cin>>n>>Q;
    if(n<=100 and Q<=100) solve100();
    else solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 339 ms 59856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 367 ms 59988 KB Output is correct
2 Correct 398 ms 60320 KB Output is correct
3 Correct 408 ms 60936 KB Output is correct
4 Correct 346 ms 59724 KB Output is correct
5 Correct 360 ms 60168 KB Output is correct
6 Correct 381 ms 60852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 339 ms 59856 KB Output isn't correct
2 Halted 0 ms 0 KB -