답안 #801996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
801996 2023-08-02T08:58:31 Z hat0412 Radio (COCI22_radio) C++14
0 / 110
166 ms 14112 KB
#include <bits/stdc++.h>

#define lli long long
#define lld long double
#define pb push_back
#define fi first
#define se second
#define name "radio"

using namespace std;

const int N = 1e5 + 10;
const int inf = 1e9 + 7;

struct Segment
{
    vector<int> st;

    void init (int n)
    {
        st.resize(n * 4 + 10);
        for (int i = 1; i <= n * 4; i++) st[i] = inf;
    }

    void update(int id, int l, int r, int u, int val)
    {
        if (u < l || u > r) return;
        if (l == r)
        {
            st[id] = val;
            return;
        }

        int m = (l + r) >> 1;
        update(id << 1, l, m, u, val);
        update(id << 1 | 1, m + 1, r, u, val);

        st[id] = min(st[id << 1], st[id << 1 | 1]);
    }

    int query (int id, int l, int r, int u, int v)
    {
        if (v < l || u > r) return inf;
        if (u <= l && r <= v) return st[id];

        int m = (l + r) >> 1;
        return min(query(id << 1, l, m, u, v),
                   query(id << 1 | 1, m + 1, r, u, v));
    }
} seg;
int n, q, prime[N], nxt[N];
set<int> pos[N];
bool check[N];

void read()
{
    cin >> n >> q;
}

void solve()
{
    for (int i = 1; i <= n; i++) nxt[i] = inf;
    for (int i = 2; i <= 100000; i++)
        if (!prime[i])
            for (int j = i; j <= 100000; j += i) if (!prime[j]) prime[j] = i;

    seg.init(n);
    while (q--)
    {
        char c; cin >> c;
        if (c == 'C')
        {
            int l, r; cin >> l >> r;
            if (seg.query(1, 1, n, l, r) <= r) cout << "YES\n";
            else cout << "NO\n";
            continue;
        }
        int x, t; cin >> x; t = x;
        if (check[x])
        {
            while (x != 1)
            {
                int s = prime[x];
                while (x % s == 0) x /= s;
                auto it1 = pos[s].upper_bound(t),
                     it2 = pos[s].lower_bound(t);

                if (it2 != pos[s].begin())
                {
                    it2--;
                    int tmp = inf;
                    if (it1 != pos[s].end()) tmp = *it1;
                    if (nxt[*it2] == t)
                    {
                        int z = *it2;
                        nxt[*it2] = tmp;

                        while (z > 1)
                        {
                            int ss = prime[z];
                            while (z % ss == 0) z /= ss;
                            auto it = pos[ss].upper_bound(t);
                            if (it != pos[ss].end()) nxt[*it2] = min(nxt[*it2], *it);
                        }

                        seg.update(1, 1, n, *it2, nxt[*it2]);
                    }
                }
                pos[s].erase(t);
            }
            nxt[t] = inf;
            seg.update(1, 1, n, t, nxt[t]);
        }
        else
        {
            while (x != 1)
            {
                int s = prime[x];
                while (x % s == 0) x /= s;
                auto it = pos[s].upper_bound(t);
                if (it != pos[s].end()) nxt[t] = min(nxt[t], *it);
                if (it != pos[s].begin())
                {
                    it--;
                    nxt[*it] = min(nxt[*it], t);
                    seg.update(1, 1, n, *it, nxt[*it]);
                }
                pos[s].insert(t);
            }
            seg.update(1, 1, n, t, nxt[t]);
        }
        check[t] ^= 1;
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }

    read();
    solve();
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:143:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  143 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:144:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  144 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 5332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 166 ms 14112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 5332 KB Output isn't correct
2 Halted 0 ms 0 KB -