답안 #1052729

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052729 2024-08-10T19:59:55 Z Ludissey Infinite Race (EGOI24_infiniterace2) C++17
100 / 100
14 ms 10584 KB
#include <bits/stdc++.h>
#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()


namespace std {

// https://judge.yosupo.jp/submission/193613
struct IOPre {
    static constexpr int TEN = 10, SZ = TEN * TEN * TEN * TEN;
    std::array<char, 4 * SZ> num;
    constexpr IOPre() : num{} {
        for (int i = 0; i < SZ; i++) for (int n = i, j = 3; j >= 0; j--) num[i * 4 + j] = n % TEN + '0', n /= TEN;
    }
};

struct IO {
#if !HAVE_DECL_FREAD_UNLOCKED
    #define fread_unlocked fread
#endif
#if !HAVE_DECL_FWRITE_UNLOCKED
    #define fwrite_unlocked fwrite
#endif
    static constexpr int SZ = 1 << 17, LEN = 32, TEN = 10, HUNDRED = TEN * TEN,
                         THOUSAND = HUNDRED * TEN, TENTHOUSAND = THOUSAND * TEN,
                         MAGIC_MULTIPLY = 205, MAGIC_SHIFT = 11, MASK = 15,
                         TWELVE = 12, SIXTEEN = 16;
    static constexpr IOPre io_pre = {};
    std::array<char, SZ> input_buffer, output_buffer;
    int input_ptr_left, input_ptr_right, output_ptr_right;

    IO() : input_buffer{}, output_buffer{}, input_ptr_left{}, input_ptr_right{}, output_ptr_right{} {}
    IO(const IO&) = delete;
    IO(IO&&) = delete;
    IO& operator=(const IO&) = delete;
    IO& operator=(IO&&) = delete;
    ~IO() { flush(); }

    template<typename T> static constexpr bool is_char_v    = std::is_same_v<T, char>;
    template<typename T> static constexpr bool is_bool_v    = std::is_same_v<T, bool>;
    template<typename T> static constexpr bool is_string_v  =
            std::is_same_v<T, std::string> || std::is_same_v<T, const char*> ||
            std::is_same_v<T, char*> || std::is_same_v< std::decay_t<T>, char*>;
    template<typename T> static constexpr bool is_default_v =
            is_char_v<T> || is_bool_v<T> || is_string_v<T> || std::is_integral_v<T>;

    inline void load() {
        memmove(std::begin(input_buffer),
                std::begin(input_buffer) + input_ptr_left,
                input_ptr_right - input_ptr_left);
        input_ptr_right =
            input_ptr_right - input_ptr_left +
            fread_unlocked(
                std::begin(input_buffer) + input_ptr_right - input_ptr_left, 1,
                SZ - input_ptr_right + input_ptr_left, stdin);
        input_ptr_left = 0;
    }

    inline void read_char(char& c) {
        if (input_ptr_left + LEN > input_ptr_right) load();
        c = input_buffer[input_ptr_left++];
    }
    inline void read_string(std::string& x) {
        char c;
        while (read_char(c), c < '!') continue;
        x = c;
        while (read_char(c), c >= '!') x += c;
    }
    template<typename T>
    inline std::enable_if_t<std::is_integral_v<T>, void> read_int(T& x) {
        if (input_ptr_left + LEN > input_ptr_right) load();
        char c = 0;
        do c = input_buffer[input_ptr_left++];
        while (c < '-');
        [[maybe_unused]] bool minus = false;
        if constexpr (std::is_signed<T>::value == true)
            if (c == '-') minus = true, c = input_buffer[input_ptr_left++];
        x = 0;
        while (c >= '0')
            x = x * TEN + (c & MASK), c = input_buffer[input_ptr_left++];
        if constexpr (std::is_signed<T>::value == true)
            if (minus) x = -x;
    }

    inline void skip_space() {
        if (input_ptr_left + LEN > input_ptr_right) load();
        while (input_buffer[input_ptr_left] <= ' ') input_ptr_left++;
    }

    inline void flush() {
        fwrite_unlocked(std::begin(output_buffer), 1, output_ptr_right, stdout);
        output_ptr_right = 0;
    }

    inline void write_char(char c) {
        if (output_ptr_right > SZ - LEN) flush();
        output_buffer[output_ptr_right++] = c;
    }

    inline void write_bool(bool b) {
        if (output_ptr_right > SZ - LEN) flush();
        output_buffer[output_ptr_right++] = b ? '1' : '0';
    }

    inline void write_string(const std::string& s) {
        for (auto x : s) write_char(x);
    }

    inline void write_string(const char* s) {
        while (*s) write_char(*s++);
    }

    inline void write_string(char* s) {
        while (*s) write_char(*s++);
    }

    template <typename T>
    inline std::enable_if_t< std::is_integral_v<T>, void> write_int(T x) {
        if (output_ptr_right > SZ - LEN) flush();
        if (!x) {
            output_buffer[output_ptr_right++] = '0';
            return;
        }
        if constexpr (std::is_signed_v<T>) if (x < 0) output_buffer[output_ptr_right++] = '-', x = -x;
        int i = TWELVE;
        std::array<char, SIXTEEN> buf{};
        for (; x >= TENTHOUSAND; x /= TENTHOUSAND, i -= 4)
            memcpy(std::begin(buf) + i, std::begin(io_pre.num) + (x % TENTHOUSAND) * 4, 4);
        if (x < HUNDRED) {
            if (x < TEN) output_buffer[output_ptr_right++] = '0' + x;
            else {
                uint32_t q = (uint32_t(x) * MAGIC_MULTIPLY) >> MAGIC_SHIFT;
                uint32_t r = uint32_t(x) - q * TEN;
                output_buffer[output_ptr_right++] = '0' + q;
                output_buffer[output_ptr_right++] = '0' + r;
            }
        } else {
            if (x < THOUSAND) 
                memcpy(std::begin(output_buffer) + output_ptr_right, std::begin(io_pre.num) + (x << 2) + 1, 3),
                output_ptr_right += 3;
            else
                memcpy(std::begin(output_buffer) + output_ptr_right, std::begin(io_pre.num) + (x << 2), 4),
                output_ptr_right += 4;
        }
        memcpy(std::begin(output_buffer) + output_ptr_right, std::begin(buf) + i + 4, TWELVE - i);
        output_ptr_right += TWELVE - i;
    }

    template <typename T_>
    std::enable_if_t<(is_default_v< std::remove_cv_t< std::remove_reference_t<T_> > >), IO&> operator<<(T_&& x) {
        using T = std::remove_cv_t< std::remove_reference_t<T_> >;
        if constexpr (is_bool_v<T>) write_bool(x);
        else if constexpr (is_string_v<T>) write_string(x);
        else if constexpr (is_char_v<T>) write_char(x);
        else if constexpr (std::is_integral_v<T>) write_int(x);
        return *this;
    }

    template<typename T>
    std::enable_if_t<(is_default_v<T> && !is_bool_v<T>), IO&> operator>>(T& x) {
        if constexpr (is_string_v<T>) read_string(x);
        else if constexpr (is_char_v<T>) read_char(x);
        else if constexpr (std::is_integral_v<T>) read_int(x);
        return *this;
    }

    IO* tie(std::nullptr_t) { return this; }
    void sync_with_stdio(bool) {}
} io;

} // namespace std

using std::io;

#define cin io
#define cout io

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> a(N,0);
    vector<int> c(N,0);
    unordered_set<int> st;
    int Q; cin >> Q;
    int mn=0;
    int lp=0;
    for (int i = 0; i < Q; i++)
    {
        int x; cin >> x;
        if(x<0) {
            a[abs(x)]=0;
        }
        else {
            if(a[x]==0){
                a[x]++;
                c[x]=lp;
            }else{
                mn++;
                a[x]=1;
                st.insert(c[x]);
                lp=max(lp,c[x]+1);
                c[x]=lp;
                
            }
        }
    }
    cout << sz(st) << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 4 ms 3256 KB Output is correct
5 Correct 5 ms 3252 KB Output is correct
6 Correct 4 ms 3256 KB Output is correct
7 Correct 4 ms 3256 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 12 ms 10500 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 4 ms 3436 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 5 ms 3500 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 11 ms 10532 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 11 ms 10448 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 4 ms 4824 KB Output is correct
6 Correct 2 ms 3676 KB Output is correct
7 Correct 9 ms 6636 KB Output is correct
8 Correct 7 ms 5740 KB Output is correct
9 Correct 5 ms 3436 KB Output is correct
10 Correct 4 ms 2488 KB Output is correct
11 Correct 4 ms 1884 KB Output is correct
12 Correct 4 ms 1628 KB Output is correct
13 Correct 5 ms 2388 KB Output is correct
14 Correct 8 ms 5208 KB Output is correct
15 Correct 8 ms 4956 KB Output is correct
16 Correct 7 ms 4852 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 10 ms 9548 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 11 ms 9648 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 3676 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 4 ms 3256 KB Output is correct
5 Correct 5 ms 3252 KB Output is correct
6 Correct 4 ms 3256 KB Output is correct
7 Correct 4 ms 3256 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 12 ms 10500 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 4 ms 3436 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 5 ms 3500 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 11 ms 10532 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 11 ms 10448 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 0 ms 600 KB Output is correct
25 Correct 4 ms 4824 KB Output is correct
26 Correct 2 ms 3676 KB Output is correct
27 Correct 9 ms 6636 KB Output is correct
28 Correct 7 ms 5740 KB Output is correct
29 Correct 5 ms 3436 KB Output is correct
30 Correct 4 ms 2488 KB Output is correct
31 Correct 4 ms 1884 KB Output is correct
32 Correct 4 ms 1628 KB Output is correct
33 Correct 5 ms 2388 KB Output is correct
34 Correct 8 ms 5208 KB Output is correct
35 Correct 8 ms 4956 KB Output is correct
36 Correct 7 ms 4852 KB Output is correct
37 Correct 0 ms 604 KB Output is correct
38 Correct 0 ms 604 KB Output is correct
39 Correct 10 ms 9548 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 11 ms 9648 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 3676 KB Output is correct
44 Correct 0 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 0 ms 604 KB Output is correct
47 Correct 0 ms 604 KB Output is correct
48 Correct 0 ms 604 KB Output is correct
49 Correct 0 ms 600 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 600 KB Output is correct
52 Correct 0 ms 604 KB Output is correct
53 Correct 0 ms 600 KB Output is correct
54 Correct 0 ms 604 KB Output is correct
55 Correct 1 ms 600 KB Output is correct
56 Correct 0 ms 600 KB Output is correct
57 Correct 0 ms 600 KB Output is correct
58 Correct 0 ms 600 KB Output is correct
59 Correct 0 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 0 ms 604 KB Output is correct
62 Correct 0 ms 604 KB Output is correct
63 Correct 0 ms 604 KB Output is correct
64 Correct 0 ms 604 KB Output is correct
65 Correct 0 ms 604 KB Output is correct
66 Correct 0 ms 604 KB Output is correct
67 Correct 0 ms 604 KB Output is correct
68 Correct 1 ms 600 KB Output is correct
69 Correct 0 ms 600 KB Output is correct
70 Correct 1 ms 604 KB Output is correct
71 Correct 0 ms 600 KB Output is correct
72 Correct 5 ms 3256 KB Output is correct
73 Correct 5 ms 3252 KB Output is correct
74 Correct 5 ms 3508 KB Output is correct
75 Correct 5 ms 3256 KB Output is correct
76 Correct 0 ms 604 KB Output is correct
77 Correct 0 ms 604 KB Output is correct
78 Correct 10 ms 10416 KB Output is correct
79 Correct 0 ms 604 KB Output is correct
80 Correct 1 ms 1116 KB Output is correct
81 Correct 0 ms 604 KB Output is correct
82 Correct 4 ms 3256 KB Output is correct
83 Correct 0 ms 604 KB Output is correct
84 Correct 4 ms 3328 KB Output is correct
85 Correct 0 ms 604 KB Output is correct
86 Correct 11 ms 10584 KB Output is correct
87 Correct 1 ms 600 KB Output is correct
88 Correct 4 ms 4956 KB Output is correct
89 Correct 1 ms 3676 KB Output is correct
90 Correct 8 ms 6580 KB Output is correct
91 Correct 9 ms 5992 KB Output is correct
92 Correct 4 ms 3516 KB Output is correct
93 Correct 4 ms 2488 KB Output is correct
94 Correct 4 ms 1884 KB Output is correct
95 Correct 3 ms 1484 KB Output is correct
96 Correct 5 ms 2400 KB Output is correct
97 Correct 7 ms 4952 KB Output is correct
98 Correct 8 ms 5068 KB Output is correct
99 Correct 7 ms 5012 KB Output is correct
100 Correct 0 ms 604 KB Output is correct
101 Correct 0 ms 604 KB Output is correct
102 Correct 11 ms 9580 KB Output is correct
103 Correct 0 ms 604 KB Output is correct
104 Correct 12 ms 9640 KB Output is correct
105 Correct 0 ms 604 KB Output is correct
106 Correct 0 ms 604 KB Output is correct
107 Correct 0 ms 604 KB Output is correct
108 Correct 1 ms 600 KB Output is correct
109 Correct 0 ms 720 KB Output is correct
110 Correct 1 ms 604 KB Output is correct
111 Correct 0 ms 604 KB Output is correct
112 Correct 8 ms 4956 KB Output is correct
113 Correct 4 ms 2652 KB Output is correct
114 Correct 6 ms 4956 KB Output is correct
115 Correct 5 ms 2396 KB Output is correct
116 Correct 14 ms 9580 KB Output is correct
117 Correct 1 ms 3676 KB Output is correct
118 Correct 4 ms 3512 KB Output is correct
119 Correct 5 ms 2484 KB Output is correct
120 Correct 4 ms 2232 KB Output is correct
121 Correct 5 ms 1936 KB Output is correct
122 Correct 5 ms 1628 KB Output is correct
123 Correct 4 ms 1628 KB Output is correct
124 Correct 5 ms 2656 KB Output is correct
125 Correct 8 ms 4952 KB Output is correct
126 Correct 8 ms 4952 KB Output is correct
127 Correct 7 ms 4956 KB Output is correct
128 Correct 9 ms 6564 KB Output is correct
129 Correct 6 ms 5296 KB Output is correct
130 Correct 1 ms 604 KB Output is correct
131 Correct 0 ms 604 KB Output is correct
132 Correct 0 ms 604 KB Output is correct
133 Correct 1 ms 3676 KB Output is correct
134 Correct 0 ms 604 KB Output is correct