#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
#define eb emplace_back
#define pb push_back
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rloop(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
unordered_set<int> kam;
vb w;
int n;
int solve()
{
if (kam.size() <= 1)
return kam.size();
int res = 1;
loop(i, 2, n + 1)
{
vi licz(n);
auto it = kam.begin();
while (it!=kam.end())
{
int indKam = *it;
licz[indKam % i]++;
res = max(res, licz[indKam % i]);
it++;
}
}
return res;
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
int q, a;
cin >> n >> q;
w.resize(n);
while (q--)
{
cin >> a; a--;
w[a] = !w[a];
if (w[a])
kam.insert(a);
else
kam.erase(a);
cout << solve() << '\n';
}
}
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 | #include <bits/stdc++.h> #include <unordered_set> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<vi> vvi; typedef vector<bool> vb; #define eb emplace_back #define pb push_back #define loop(i, a, b) for (int i = a; i < b; i++) #define rloop(i, a, b) for (int i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() unordered_set<int> kam; vb w; int n; int solve() { if (kam.size() <= 1) return kam.size(); int res = 1; loop(i, 2, n + 1) { vi licz(n); auto it = kam.begin(); while (it!=kam.end()) { int indKam = *it; licz[indKam % i]++; res = max(res, licz[indKam % i]); it++; } } return res; } int main() { cin.tie(0)->sync_with_stdio(false); int q, a; cin >> n >> q; w.resize(n); while (q--) { cin >> a; a--; w[a] = !w[a]; if (w[a]) kam.insert(a); else kam.erase(a); cout << solve() << '\n'; } } |
English