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
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second

typedef long long ll;

const int B = 450; 

int n, q;
vector<char> has_kam; 

vector<int> ile_mod;
int off_k[B + 1];

vector<int> freq_wyn;
int off_freq[B + 1];
int max_k[B + 1];

vector<int> act_kam;
bool V_maintained = 1;
int akt_max = 0;

void init(int n_val){

	has_kam.assign(n_val + 1, 0);
	act_kam.reserve(25000); 
	
	int tot_cnt = 0;
	int tot_freq = 0;

	for(int k = 2; k <= B; k++){

		off_k[k] = tot_cnt;
		tot_cnt += k;
		
		off_freq[k] = tot_freq;
		int max_score = (n_val + k - 1) / k; 
		tot_freq += (max_score + 2);
	}
	
	ile_mod.assign(tot_cnt, 0);
	freq_wyn.assign(tot_freq, 0);

	for(int k = 2; k <= B; k++){

		max_k[k] = 0;
		freq_wyn[off_freq[k] + 0] = k; 
	}
}

void update(int x){

	bool adding = !has_kam[x];
	has_kam[x] = adding;
	
	if(V_maintained){

		auto it = lower_bound(act_kam.begin(), act_kam.end(), x);
		if(adding) act_kam.insert(it, x);
		else act_kam.erase(it);
	}

	akt_max = 0;

	if(adding){

		for(int k = 2; k <= B; k++){

			int c_idx = off_k[k] + (x % k);
			int old_v = ile_mod[c_idx];
			int new_v = old_v + 1;
			
			ile_mod[c_idx] = new_v;

			int f_base = off_freq[k];
			freq_wyn[f_base + old_v]--;
			freq_wyn[f_base + new_v]++;

			if(new_v > max_k[k]) max_k[k] = new_v;
			if(max_k[k] > akt_max) akt_max = max_k[k];
		}
	} 
	else {

		for(int k = 2; k <= B; k++){

			int c_idx = off_k[k] + (x % k);
			int old_v = ile_mod[c_idx];
			int new_v = old_v - 1;
			
			ile_mod[c_idx] = new_v;

			int f_base = off_freq[k];
			freq_wyn[f_base + old_v]--;
			freq_wyn[f_base + new_v]++;

			if(old_v == max_k[k] && freq_wyn[f_base + old_v] == 0) max_k[k]--; 
			if(max_k[k] > akt_max) akt_max = max_k[k];
		}
	}

	int limit_K = (n - 1) / max(1, akt_max);
	
	if(V_maintained && B >= limit_K){

		V_maintained = 0;
		act_kam.clear();
		act_kam.shrink_to_fit();
	} 
	else if(!V_maintained && B < limit_K){

		V_maintained = 1;
		act_kam.clear();
		
		for(int i = 0; i < n; i++){

			if(has_kam[i]) act_kam.push_back(i);
		}
	}
}

int get_wynik(){

	int best = akt_max;
	
	if(!V_maintained) return best;
	int sz = act_kam.size();
	
	if(sz <= 1) return sz;
	if(best < 2) best = 2;

	int j_start = 0; 
	
	for(int i = 0; i < sz; i++){

		int max_K = (n - 1 - act_kam[i]) / best;		
		if(B >= max_K) continue; 
		j_start = max(j_start, i + 1);		
		while(j_start < sz && act_kam[j_start] - act_kam[i] <= B) j_start++;
		
		for(int j = j_start; j < sz; j++){

			int K = act_kam[j] - act_kam[i];
			
			if(K > max_K) break; 
			if(act_kam[i] >= K && has_kam[act_kam[i] - K]) continue;
			
			int cur = 2; 
			int nxt = act_kam[j] + K;
			
			while(nxt < n && has_kam[nxt]){

				cur++;
				nxt += K;
			}
			
			if(cur > best){

				best = cur;
				max_K = (n - 1 - act_kam[i]) / best; 
			}
		}
	}
	
	return best;
}

void solve(){

	cin >> n >> q;
	init(n);

	for(int i = 0; i < q; i++){

		int x;
		cin >> x;
		x--; 
		
		update(x);
		cout << get_wynik() << '\n';
	}
}

bool multi = 0;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int t = 1;
	if(multi) cin >> t;
	
	while(t--){

		solve();
	}

	return 0;
}