提出 #27419054


ソースコード 拡げる

// {{{
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using vi = vector<int>;
using pii = pair<int, int>;
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define debug(x...)
#define debug_arr(x...)
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
// }}}

const int N = (1 << 20);

LL v[N];
set<int> st;
int q;

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif

    ios::sync_with_stdio(false);
    cin.tie(0);

    while (cin >> q)
    {
        st.clear();
        for (int i = 0; i < (1 << 20); i++) st.insert(i);

        for (int i = 0; i < q; ++i)
        {
            int t;
            LL x;
            cin >> t >> x;
            if (t == 1)
            {
                int h = x % (1 << 20);

                auto iter = st.lower_bound(h);
                if (iter == st.end()) iter = st.begin();

                v[*iter] = x;
                st.erase(iter);
            }
            else
            {
                int h = x % (1 << 20);
                if (st.find(h) != st.end())
                {
                    cout << -1 << '\n';
                }
                else
                    cout << v[h] << '\n';
            }
        }
    }

    return 0;
}

提出情報

提出日時
問題 D - Linear Probing
ユーザ mickeyandkaka
言語 C++ (GCC 9.2.1)
得点 400
コード長 1441 Byte
結果 AC
実行時間 434 ms
メモリ 60912 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 1
AC × 18
セット名 テストケース
Sample example_00.txt
All additional.txt, example_00.txt, max.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt
ケース名 結果 実行時間 メモリ
additional.txt AC 321 ms 53340 KiB
example_00.txt AC 250 ms 52612 KiB
max.txt AC 303 ms 54160 KiB
test_00.txt AC 434 ms 60860 KiB
test_01.txt AC 434 ms 60908 KiB
test_02.txt AC 262 ms 60384 KiB
test_03.txt AC 343 ms 60748 KiB
test_04.txt AC 393 ms 60904 KiB
test_05.txt AC 351 ms 60748 KiB
test_06.txt AC 347 ms 60912 KiB
test_07.txt AC 355 ms 60912 KiB
test_08.txt AC 326 ms 60812 KiB
test_09.txt AC 292 ms 60820 KiB
test_10.txt AC 343 ms 53844 KiB
test_11.txt AC 343 ms 53852 KiB
test_12.txt AC 284 ms 53348 KiB
test_13.txt AC 328 ms 53616 KiB
test_14.txt AC 331 ms 53712 KiB