#include <bits/stdc++.h>
using namespace std;
const int MX = 1e7+9;
unordered_set<int>pos;
int mod[MX];
int get(){
int x = 0;
char c = getchar_unlocked();
while(c < '0' || c > '9') c = getchar_unlocked();
while(c >= '0' && c <= '9'){
x = x*10+c-'0';
c = getchar_unlocked();
}
return x;
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int n = get(), q = get();
while(q--){
int x = get(), res = 0;
auto it = pos.find(x);
if(it == pos.end()) pos.insert(x);
else pos.erase(it);
int m = pos.size();
for(auto k = 2; k <= 2*(n/m); ++k){
for(auto it : pos) mod[it%k]++;
for(auto it : pos){
res = max(res, mod[it%k]);
mod[it%k] = 0;
}
}
cout << res << endl;
}
}
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 | #include <bits/stdc++.h> using namespace std; const int MX = 1e7+9; unordered_set<int>pos; int mod[MX]; int get(){ int x = 0; char c = getchar_unlocked(); while(c < '0' || c > '9') c = getchar_unlocked(); while(c >= '0' && c <= '9'){ x = x*10+c-'0'; c = getchar_unlocked(); } return x; } int main(){ cin.tie(0)->sync_with_stdio(0); int n = get(), q = get(); while(q--){ int x = get(), res = 0; auto it = pos.find(x); if(it == pos.end()) pos.insert(x); else pos.erase(it); int m = pos.size(); for(auto k = 2; k <= 2*(n/m); ++k){ for(auto it : pos) mod[it%k]++; for(auto it : pos){ res = max(res, mod[it%k]); mod[it%k] = 0; } } cout << res << endl; } } |
English