1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;


namespace BR {

const int N = 10'000'007;

int il[N];
int tab[N], gdz[N], m = 0;

int C(int n)
{
    int ans = (m + 1) / 2;
    for(int i = 2; i <= n; ++i)
    {
        if(((n + i - 1) / i) <= ans) break;
        for(int j = 1; j <= m; ++j)
            ++il[tab[j] % i];
        for(int j = 1; j <= m; ++j)
        {
            ans = max(ans, il[tab[j] % i]);
            il[tab[j] % i] = 0;
        }
    }
    return ans;
}

void Solve(int n, int q)
{
    int a;
    for(int i = 1; i <= q; ++i)
    {
        scanf("%d", &a);
        if(gdz[a] != 0)
        {
            gdz[tab[m]] = gdz[a];
            swap(tab[m], tab[gdz[a]]);
            gdz[a] = 0;
            --m;
        }else
        {
            ++m;
            tab[m] = a;
            gdz[a] = m;
        }
        // cout << "S: " << i << " " << m << "\n";
        int ans = C(n);
        printf("%d\n", ans);
    }
}
}



const ll I = 1'000'000'000'000'000'000LL;
const int II = 2'000'000'000;
const ll M = 1'000'000'007LL;
const int N = 10'000'007;
const int NN = 1'000'007;
const int K = 900;
const int K2 = 1800;
int L = (N - 7) / ((K + 1) / 2);
const int P = 5000;

const ll TIME = chrono::high_resolution_clock::now().time_since_epoch().count();
const ll SEED = (ll)(new ll);
const ll RANDOM = TIME ^ SEED;
const ll MOD = (int)1e9+7;
const ll MUL = (int)1e6+3;

struct chash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

gp_hash_table<int, int, chash> lic[NN];
int lic2[1000][5000];

vector<int> dv[N]; int num[N], lp[N];
int wh[N], tab[NN], m = 0;

int il[NN], ans = 0;

void Sito(int n)
{
    int xd = 0;
    for(int i = 2; i <= n / 2; ++i)
    {
        if((int)dv[i].size() > 0) continue;
        num[i] = (++xd); lp[num[i]] = i;
        for(int j = i; j <= n; j += i)
            dv[j].pb(i);
    }
    lp[xd + 1] = II;
}

void Upd(int v)
{
    if(wh[v])
    {
        wh[tab[m]] = wh[v];
        swap(tab[wh[v]], tab[m]);
        --m; wh[v] = 0;
    }else
    {
        ++m; wh[v] = m;
        tab[m] = v;
    }
}

int vis[N], el[N];

void Add1(int v, int c) {
    int a, cnt = 0;
    for(int i = 1; i <= m; ++i)
    {
        int a = tab[i];
        int d = abs(v - a);
        if(d <= 1) continue;
            for(int j = 0; j < (int)dv[d].size(); ++j)
                if(vis[dv[d][j]] == 0)
                    {el[++cnt] = dv[d][j]; vis[dv[d][j]] = 1;}
    }
    // cout << "A1\n";
    for(int i = 1; i <= cnt; ++i)
    {
        a = 0; int p = num[el[i]], r = v % (el[i]);
        if(lp[p] > P && lic[p].find(r) != lic[p].end())
            a = lic[p][r];
        if(lp[p] <= P)
            a = lic2[p][r];
        // cout << "A: " << v << " " << el[i] << " " << r << " " << a << "\n";
        if(a == 0 || (a == 2 && c == -1))
            c *= 2;
        --il[a];
        ++il[a + c];
        if(lp[p] > P)
            lic[p][r] = a + c;
        else
            lic2[p][r] = a + c;
        
        if(abs(c) > 1)
            c /= 2;

        vis[el[i]] = 0;
    }
    // cout << "F: " << ans << " " << il[ans + 1] << " " << il[ans + 2] << "\n";
    if(il[ans + 2] > 0)
        ans += 2;
    if(il[ans + 1] > 0)
        ++ans;
    while(il[ans] == 0 && ans > 0)
        --ans;
}

void Trans2()
{
    il[0] = II; ans = max(ans, (m + 1) / 2);
    int a = 0, r;
    int j;
    for(j = 1; lp[j] <= min(L, P); ++j)
        for(int i = 1; i <= m; ++i)
        {
            a = 0; r = tab[i] % lp[j];
            a = lic2[j][r];
            
            if(a != 0) continue;
            --il[a];
            ++il[a + 1];
            
            lic2[j][r] = a + 1;
            ans = max(ans, a + 1);
        }
    for(j = j; lp[j] <= L; ++j)
        for(int i = 1; i <= m; ++i)
        {
            a = 0; r = tab[i] % lp[j];
            if(lic[j].find(r) != lic[j].end())
                a = lic[j][r];
            if(a != 0) continue;
            --il[a];
            ++il[a + 1];
            if(lp[j] > P)
                lic[j][r] = a + 1;
            ans = max(ans, a + 1);
        }
}

void Add2(int v, int c)
{
    int a, r, j;
    for(j = 1; lp[j] <= min(L, P); ++j)
    {
        a = 0; r = v % lp[j];
        a = lic2[j][r];
        
        --il[a];
        ++il[a + c];
        
        lic2[j][r] = a + c;
    }
    for(j = j; lp[j] <= L; ++j)
    {
        a = 0; r = v % lp[j];
        if(lic[j].find(r) != lic[j].end())
            a = lic[j][r];

        --il[a];
        ++il[a + c];

        lic[j][r] = a + c;
    }
    if(il[ans + 1] > 0)
        ++ans;
    if(il[ans] == 0)
        --ans;
}

void Trans1()
{
    int r;
    il[0] = II; il[1] = 0;
    if(ans == 1) ans = 0;
    for(int j = 1; lp[j] <= L; ++j)
        for(int i = 1; i <= m; ++i)
        {
            r = tab[i] % lp[j];
            if(lp[j] <= P)
            {
                if(lic2[j][r] == 1)
                    lic2[j][r] = 0;
            }else
            {
                if(lic[j][r] == 1)
                    lic[j][r] = 0;
            }
        }
}

void Solve()
{
    il[0] = II;
    int n, q, a, mode = 1;
    scanf("%d %d", &n, &q);

    if(n * q <= 10 * N)
    {
        BR::Solve(n, q);
        return;
    }

    Sito(n);
    L = (n - 7) / ((K + 1) / 2);
    for(int i = 1; i <= q; ++i)
    {
        scanf("%d", &a);
        int c = 1;
        if(wh[a] != 0)
            c = -1;
        if(mode == 1)
            Add1(a, c);
        else
            Add2(a, c);
        Upd(a);

        int res = max(min(1, m), ans);
        if(m > 2 || (m == 2 && min(tab[1], tab[2]) + 1 != max(tab[1], tab[2])))
            res = max(res, 2);
        printf("%d\n", res);
        if(mode == 1 && m >= K2)
        {
            Trans2();
            mode = 2;
        }else if(mode == 2 && m <= K)
        {
            Trans1();
            mode = 1;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // Sito();
    Solve();

    return 0;
}