Submission #1012753

# Submission time Handle Problem Language Result Execution time Memory
1012753 2024-07-02T14:40:47 Z TrinhKhanhDung Radio (COCI22_radio) C++14
0 / 110
734 ms 141344 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(), v.end()
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(k) (1LL << (k))
#define MOD (ll)(1e9 + 7)
#define INF (ll)1e9
#define oo (ll)1e18

using namespace std;

template<class T1, class T2>
    bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

template<class T1, class T2>
    bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}

template<class T1, class T2>
    void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}

template<class T1, class T2>
    void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}

template<class T>
    void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}

const int MAX = 1e6 + 10;

vector<int> prime[MAX];
int cnt[MAX], k[MAX], a[MAX];
set<int> st[MAX];
int N, Q;

int Max[MAX * 4];

void update(int p, int ma){
    int i = 1, l = 1, r = N;
    while(l < r){
        int m = (l + r) >> 1;
        if(p <= m){
            i = i * 2;
            r = m;
        }
        else{
            i = i * 2 + 1;
            l = m + 1;
        }
    }
    Max[i] = ma;
    while(i > 1){
        i >>= 1;
        Max[i] = max(Max[i * 2], Max[i * 2 + 1]);
    }
}

int getVal(int i, int l, int r, int u, int v){
    if(r < u || v < l) return 0;
    if(u <= l && r <= v) return Max[i];
    int m = (l + r) >> 1;
    int L = getVal(i * 2, l, m, u, v);
    int R = getVal(i * 2 + 1, m + 1, r, u, v);
    return max(L, R);
}

int getVal(int u, int v){
    return getVal(1, 1, N, u, v);
}

void change(int x){
    int ma = 0;
    for(int k: prime[x]){
        auto it = st[k].lower_bound(x);
        if(it == st[k].begin()) continue;
        it--;
        maximize(ma, *it);
    }
    update(x, ma);
}

void solve(){
    for(int i=2; i<MAX; i++) if(cnt[i] == 0){
        for(int j=i; j<MAX; j+=i){
            cnt[j]++;
        }
    }
    for(int i=2; i<MAX; i++){
        prime[i].resize(cnt[i]);
    }
    for(int i=2; i<MAX; i++) if(k[i] == 0){
        for(int j=i; j<MAX; j+=i){
            prime[j][k[j]++] = i;
        }
    }

//    for(int i=2; i<=10; i++){
//        for(int j:prime[i]) cout << j << ' ';
//        cout << '\n';
//    }

    cin >> N >> Q;

    for(int q=1; q<=Q; q++){
        char t; cin >> t;
        if(t == 'S'){
            int x; cin >> x;
            if(!a[x]){
                a[x] = true;
                for(int k: prime[x]){
                    st[k].insert(x);
                }
            }
            else{
                a[x] = false;
                for(int k: prime[x]){
                    st[k].erase(x);
                }
            }
            change(x);

            vector<int> node;
            for(int k: prime[x]){
                auto it = st[k].upper_bound(x);
                if(it == st[k].end()) continue;
                node.push_back(*it);
            }
            cps(node);
            for(int i: node){
                change(i);
            }
        }
        else{
            int l, r;
            cin >> l >> r;

            cout << (getVal(l, r) >= l ? "DA\n" : "NE\n");
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
//   freopen("WPRO.inp", "r", stdin);
//   freopen("WPRO.out", "w", stdout);

    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 100 ms 109908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 384 ms 118096 KB Output is correct
2 Correct 621 ms 132180 KB Output is correct
3 Correct 734 ms 141344 KB Output is correct
4 Incorrect 112 ms 111400 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 100 ms 109908 KB Output isn't correct
2 Halted 0 ms 0 KB -