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
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int nm; 
int getint() {
    nm = 0;
    char c = getchar_unlocked();
    while (c<'0' or c>'9') c = getchar_unlocked();
    nm = c - '0';
    c = getchar_unlocked();
    while (c >= '0' and c <= '9') {
        nm *= 10;
        nm += (c - '0');
        c = getchar_unlocked();
    }
    return nm;
}

inline void putint(int nm) {
    if (nm >= 10) putint(nm / 10);
    putchar_unlocked('0' + nm % 10);
}

struct FastMod {
    uint32_t b, m;
    
    FastMod() : b(1), m(0) {}
    FastMod(uint32_t b) : b(b), m((1ULL << 32) / b) {}
    
    uint32_t reduce(uint32_t a) {
        uint32_t q = (uint32_t)(((uint64_t)m * a) >> 32);
        uint32_t r = a - q * b;
        return r >= b ? r - b : r;
    }
};

FastMod fusp[455];
vector<int> kst;
int poz[10000009];

void insert(int x) {
    poz[x] = kst.size();
    kst.push_back(x);
}

void erase(int x) {
    int ind = poz[x];
    int ost = kst.back();
    kst[ind] = ost;     
    poz[ost] = ind;      
    kst.pop_back();
    poz[x] = -1;
}

int random_element() {
    return kst[rng() % kst.size()];
}

bool contains(int x) {
    return poz[x] != -1;
}

const int B = 3200;
const int T = 77;
int T1;
int n,q;
int lpf[10000009];
int w[1000][B+9];
int w2[10000009];

vector<int> primes;
vector<int> usp;
bool us[10000009];
int kct = 0;
int kam[10000009];
int wyn, wyn2, wyn3;
map<pair<int,int>, int> mp;
int m, r1, r2, k, of;


void sito(){
    for(int i=2;i<=10000000;i++){
        if(!us[i]){
            primes.push_back(i);
            if(i<=B) {
                usp.push_back(i);
                fusp[usp.size() - 1] = FastMod(i);
            }
            for(int j=i;j<=10000000;j+=i){
                us[j]=1;
                lpf[j]=i;
            }
        }
    }
}

int ctrm=0;

int main(){
    fill(poz, poz + 10000009,-1);
    sito();
    n = getint();
    q = getint();
    wyn=0;
    if(n<=1000000) T1 = 150;
    else T1=77;
    w2[0]=10000000;
    while(q--){
        int x = getint();
        
        if(kam[x]){
            kct--;
            kam[x]^=1;
            erase(x);
            for(int i=0;i<usp.size();i++){
                int m = fusp[i].reduce(x);
                w[i][m]--;
                w2[w[i][m]]++;
                w2[w[i][m]+1]--;
            }
        }
        else{
            kct++;
            kam[x]^=1;
            insert(x);
            for(int i=0;i<usp.size();i++){
                int m = fusp[i].reduce(x);
                w[i][m]++;
                w2[w[i][m]]++;
                w2[w[i][m]-1]--;
            }
        }

        if(w2[wyn+1]) wyn++;
        else if(!w2[wyn]){
            wyn--;
        }
        wyn2=0;

        if(kct>2*(n/B)) {
            ctrm++;

            goto sex;
        }

        if(kst.size()>=2){
            mp.clear();
            for(int i=0;i<T1;i++){
                r1 = random_element();
                r2 = random_element();

                k = abs(r1-r2);
                if(k<2) continue;
                of = r1%(lpf[k]);
                if(lpf[k]<=B) continue;
                mp[{lpf[k], of}]++;

                
            }
            vector<pair<int, pair<int,int>>> v;
            for (auto &i : mp) v.push_back({i.second, i.first});
            m = min<int>(2, v.size());
            partial_sort(v.begin(), v.begin() + m, v.end(), greater<>());

            for(int i=0;i<2 and i<v.size();i++){
                wyn3=0;
                for(int j=v[i].second.second;j<=n;j+=v[i].second.first){
                    if(kam[j]) wyn3++;
                }
                wyn2=max(wyn3,wyn2);
            }
        }
sex:
        putint(max(wyn,wyn2));
        putchar_unlocked('\n');

        
    }
    //putint(ctrm);


}