답안 #540832

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
540832 2022-03-21T20:17:56 Z N1NT3NDO Radio (COCI22_radio) C++14
0 / 110
1229 ms 193372 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define fi first
#define sd second
#define all(x) x.begin(), x.end()
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = (int)1e6 + 5;
int n, q, cnt, skok[N], t[4 * N];
bool was[N];
vector< int > del[N];
set < int > se[N];
multiset< int > all[N];

void build(int v, int tl, int tr)
{
    t[v] = 1e9;
    if (tl == tr) return;
    int m = (tl + tr) >> 1;
    build(v * 2, tl, m);
    build(v * 2 + 1, m + 1, tr);
}

void upd(int v, int tl, int tr, int pos, int val)
{
    if (tl == tr)
    {
        t[v] = val;
        return;
    }

    int m = (tl + tr) >> 1;

    if (pos <= m)
      upd(v * 2, tl, m, pos, val);
    else upd(v * 2 + 1, m + 1, tr, pos, val);
    t[v] = min(t[v * 2], t[v * 2 + 1]);
}

int get(int v, int tl, int tr, int l, int r)
{
    if (tl > tr || tl > r || tr < l) return 1e9;

    if (tl >= l && tr <= r) return t[v];

    int m = (tl + tr) >> 1;

    return min(get(v * 2, tl, m, l, r), get(v * 2 + 1, m + 1, tr, l, r));
}

void upd(int x)
{
    if (!x) return;

    int val = 1e9;

    if (sz(all[x]) > 0) val = *all[x].begin();

    upd(1, 1, n, x, val);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> q;

    //for(auto i : {2, 3, 5, 7, 11, 13, 17, 19})
    for(int i = 2; i <= n; i++)
    {
        if (sz(del[i])) continue;

        for(int j = i; j <= n; j += i)
            del[j].pb(i);
    }

    build(1, 1, n);

    while(q--)
    {
        char c;
        cin >> c;
        if (c == 'S')
        {
            int x;
            cin >> x;
            if (was[x])
            {
                for(auto d : del[x])
                {
                    auto it = se[d].lower_bound(x);
                    int r = 0, l = 0;
                    if ((++it) != se[d].end()) r = *it; it--;
                    if (it != se[d].begin()) l = *(--it);
                    if (l) all[l].erase(all[l].find(x));
                    if (r) all[x].erase(all[x].find(r));
                    if (l && r) all[l].insert(r);
                    upd(l); upd(r);
                    se[d].erase(x);
                }
            }
            else
            {
                for(auto d : del[x])
                {
                    auto it = se[d].upper_bound(x);
                    int r = 0, l = 0;
                    if (it != se[d].end()) r = *it;
                    if (it != se[d].begin()) l = *(--it);
                    if (l) all[l].insert(x);
                    if (r) all[x].insert(r);
                    if (l && r) all[l].erase(all[l].find(r));
                    upd(l); upd(r);
                    se[d].insert(x);
                }
            }

            was[x] ^= 1;
        }
        else
        {
            int l, r;
            cin >> l >> r;

            /*
            for(int i = 1; i <= n; i++)
            {
                if (sz(all[i]) > 0)
                {
                    cout << "! " << i << endl;
                    for(auto u : all[i]) cout << u << ' ';
                    cout << '\n';
                }

            }
            */

            if (get(1, 1, n, l, r) <= r) cout << "DA" << '\n';
            else cout << "NE" << '\n';
        }
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:102:21: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  102 |                     if ((++it) != se[d].end()) r = *it; it--;
      |                     ^~
Main.cpp:102:57: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  102 |                     if ((++it) != se[d].end()) r = *it; it--;
      |                                                         ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 54 ms 117636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 537 ms 133052 KB Output is correct
2 Correct 963 ms 166676 KB Output is correct
3 Correct 1229 ms 193372 KB Output is correct
4 Incorrect 83 ms 122016 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 54 ms 117636 KB Output isn't correct
2 Halted 0 ms 0 KB -