답안 #542493

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
542493 2022-03-26T19:05:44 Z Zhora_004 Radio (COCI22_radio) C++17
10 / 110
1500 ms 58932 KB
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#include <chrono>
#include <cassert>
#include <bitset>
//#include <bit>
//#include <ranges>
//#include <numbers>
#define itn int
#define sacnf scanf
#define sz(a) ((int)((a).size()))
// printf("%.10f\n", ans);
using ll = long long;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e6 + 1, inf = 1e9;



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, q;
    cin >> n >> q;
    vector<set<int>> id(n + 1);
    vector<vector<int>> divs(n + 1);
    for (int i = 2; i <= n; i++) if (divs[i].empty()) for (int j = i; j <= n; j += i) divs[j].push_back(i);
    vector<int> L(n + 1, -1), R(n + 1, inf);
    vector<bool> on(n + 1);
    while (q--)
    {
        char smb;
        cin >> smb;
        if (smb == 'S')
        {
            int x;
            cin >> x;
            if (on[x])
            {
                for (int& d : divs[x])
                {
                    set<int>& s = id[d];
                    s.erase(x);
                    auto it = s.upper_bound(x);
                    int l = -1, r = inf;
                    if (it != s.end()) r = *it;
                    if (it != s.begin()) l = *prev(it);
                    if (it != s.end())
                    {
                        int id1 = *it;
                        if (L[id1] == x) L[id1] = -1;
                        L[id1] = max(L[id1], l);
                    }
                    if (it != s.begin())
                    {
                        it--;
                        int id1 = *it;
                        if (R[id1] == x) R[id1] = inf;
                        R[id1] = min(R[id1], r);
                    }
                }
                L[x] = -1;
                R[x] = inf;
            }
            else
            {
                for (int& d : divs[x])
                {
                    set<int>& s = id[d];
                    auto it = s.upper_bound(x);
                    if (it == s.end()) R[x] = min(R[x], inf);
                    else R[x] = min(R[x], *it), L[*it] = max(L[*it], x);
                    if (it == s.begin()) L[x] = max(L[x], -1);
                    else it--, L[x] = max(L[x], *it), R[*it] = min(R[*it], x);
                    s.insert(x);
                }
            }
            on[x] = !on[x];
        }
        else
        {
            int l, r;
            cin >> l >> r;
            int mn = inf;
            for (int i = l; i <= r; i++) mn = min(mn, R[i]);
            if (mn <= r) cout << "DA\n";
            else cout << "NE\n";
        }
    }

    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1438 ms 16868 KB Output is correct
2 Execution timed out 1594 ms 58932 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1438 ms 16868 KB Output is correct
9 Execution timed out 1594 ms 58932 KB Time limit exceeded
10 Halted 0 ms 0 KB -