Submission #1322055

#TimeUsernameProblemLanguageResultExecution timeMemory
1322055JohanRadio (COCI22_radio)C++20
30 / 110
198 ms73436 KiB
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int INF = 1e9;
int spf[N], is[N];
set < int > st, g[N];

void precompute(){
  for(int i = 2; i < N; i++)
    spf[i] = INF;
  for(int i = 2; i < N; i++){
    if(spf[i] != INF)continue;
    for(int j = i; j < N; j += i){
      spf[j] = min(spf[j], i);
    }
  }
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  precompute();
  int n, q;
  cin >> n >> q;
  while(q--){
    char type;
    cin >> type;
    if(type == 'S'){
      int ps;
      cin >> ps;
      is[ps] ^= 1;
      int x = ps;
      while(x != 1){
        int xx = spf[x];
        if(is[ps] == 1){
          g[xx].insert(ps);
          if(g[xx].size() == 2){
            st.insert(xx);
          }
        }
        else {
          g[xx].erase(ps);
          if(g[xx].size() == 1){
            st.erase(xx);
          }
        }
        x /= xx;
      }
    }
    else {
      int l, r;
      cin >> l >> r;
      bool ok = false;
      for(auto i : st){
        auto it = g[i].lower_bound(l);
        int ql = *(it);
        int qr = *(++it);
        if(l <= ql && qr <= r){
          ok = true;
          break;
        }
      }
      cout << (ok ? "DA" : "NE") << endl;
    }
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...