提出 #35493024


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ld = long double;
using pll = pair<ll, ll>;
// and so on
int arr[200001];
int vis[200001];
int cnt[300001];
vector<int> lst[2];
vector<pii> event;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int N, Q;
    cin >> N >> Q;
    for (int i = 1; i <= N; i++) {
        cin >> arr[i];
        if (0 <= arr[i] && arr[i] <= N) {
            cnt[arr[i]]++;
            vis[i] = 1;
            event.push_back({(N - arr[i] + (i - 1)) / i, i});
            lst[0].push_back(i);
        } else if (arr[i] < 0) {
            int na = -arr[i];
            event.push_back({(na + (i - 1)) / i, i});
            event.push_back({(N + 1 + na + (i - 1)) / i + 10, i});
        }
    }
    sort(event.begin(), event.end());
    int Mex = 0, ptr = 0;
    while (cnt[Mex] > 0) Mex++;
    for (int q = 1; q <= Q; q++) {
        int nxt = q % 2;
        int cunt = 1 - nxt;
        while (ptr < (int)event.size() && event[ptr].first == q) {
            int x = event[ptr].second;
            if (vis[x]++ == 0) lst[cunt].push_back(x);
            ptr++;
        }
        for (int x : lst[cunt]) {
            if (vis[x] == 1) lst[nxt].push_back(x);
        }
        lst[cunt].clear();
        for (int i : lst[nxt]) {
            if (0 <= arr[i] + (q - 1) * i && arr[i] + (q - 1) * i <= N) {
                if (--cnt[arr[i] + (q - 1) * i] == 0)
                    Mex = min(arr[i] + (q - 1) * i, Mex);
            }
            if (0 <= arr[i] + q * i && arr[i] + q * i <= N) {
                cnt[arr[i] + q * i]++;
                while (cnt[Mex] > 0) Mex++;
            }
        }
        
        cout << Mex << '\n';
    }
}

提出情報

提出日時
問題 E - Add and Mex
ユーザ jame0313
言語 C++ (GCC 9.2.1)
得点 500
コード長 1793 Byte
結果 AC
実行時間 107 ms
メモリ 12068 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 2
AC × 35
セット名 テストケース
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt, 03_handmade_07.txt, 03_handmade_08.txt, 03_handmade_09.txt, 03_handmade_10.txt, 03_handmade_11.txt, 03_handmade_12.txt, 03_handmade_13.txt, 03_handmade_14.txt, 03_handmade_15.txt, 03_handmade_16.txt, 03_handmade_17.txt, 03_handmade_18.txt, 03_handmade_19.txt, 03_handmade_20.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 7 ms 3456 KiB
00_sample_02.txt AC 2 ms 3532 KiB
01_small_01.txt AC 2 ms 3460 KiB
01_small_02.txt AC 2 ms 3572 KiB
01_small_03.txt AC 2 ms 3488 KiB
01_small_04.txt AC 2 ms 3460 KiB
01_small_05.txt AC 2 ms 3452 KiB
02_random_01.txt AC 106 ms 8904 KiB
02_random_02.txt AC 104 ms 8684 KiB
02_random_03.txt AC 105 ms 8672 KiB
02_random_04.txt AC 104 ms 8892 KiB
02_random_05.txt AC 106 ms 8844 KiB
02_random_06.txt AC 104 ms 8764 KiB
02_random_07.txt AC 105 ms 8772 KiB
02_random_08.txt AC 69 ms 8720 KiB
03_handmade_01.txt AC 95 ms 11648 KiB
03_handmade_02.txt AC 94 ms 11712 KiB
03_handmade_03.txt AC 92 ms 11484 KiB
03_handmade_04.txt AC 95 ms 12068 KiB
03_handmade_05.txt AC 101 ms 8844 KiB
03_handmade_06.txt AC 97 ms 9396 KiB
03_handmade_07.txt AC 96 ms 12040 KiB
03_handmade_08.txt AC 100 ms 9104 KiB
03_handmade_09.txt AC 96 ms 9432 KiB
03_handmade_10.txt AC 101 ms 8704 KiB
03_handmade_11.txt AC 98 ms 8620 KiB
03_handmade_12.txt AC 107 ms 8676 KiB
03_handmade_13.txt AC 106 ms 8740 KiB
03_handmade_14.txt AC 102 ms 8684 KiB
03_handmade_15.txt AC 102 ms 8684 KiB
03_handmade_16.txt AC 103 ms 8688 KiB
03_handmade_17.txt AC 106 ms 8752 KiB
03_handmade_18.txt AC 103 ms 8748 KiB
03_handmade_19.txt AC 102 ms 8696 KiB
03_handmade_20.txt AC 102 ms 8752 KiB