constint MAXN = 2E5 + 5; constint MOD = 1E9 + 7; int n, k; LL qpow(LL a, LL b, LL MOD){ LL ans = 1, base = a; while (b) { if (b & 1) ans = ans * base % MOD; b >>= 1, base = base * base % MOD; } return ans; }
constint MAXN = 2E5 + 5; constint MOD = 1E9 + 7; int n, m, T;
signedmain(){ cin >> n; vector<int> v; LL pro = 1; for (int i = 1; i <= n - 1; i++) if (__gcd(i, n) == 1) v.push_back(i), pro = pro * i % n; if (pro != 1) v.pop_back(); cout << v.size() << endl; for (auto& val : v) cout << val << " "; return0; }
usingnamespacestd; constint MAXN = 3e5 + 5; int n, m, sz, tot; int color[MAXN], belong[MAXN], ans[MAXN], cnt[MAXN], num[MAXN]; vector<int> v;
template <classT> voidread(T& x, Tf = 1, charch = getchar()) { x = 0; while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar(); x *= f; }
structQuery { int l, r, id; friendbooloperator<(const Query& a, const Query& b) { if (belong[a.l] == belong[b.l]) { if (belong[a.l] & 1) return a.r < b.r; return a.r > b.r; } return a.l < b.l; } } q[MAXN];
voidAdd(int x){ num[cnt[x]]--; cnt[x]++; num[cnt[x]]++; tot = max(tot, cnt[x]); }
voidSub(int x){ num[cnt[x]]--; if (cnt[x] == tot && !num[cnt[x]]) tot--; cnt[x]--; num[cnt[x]]++; }
intmain(){ read(n), read(m); sz = max(1, int(n / sqrt(m))); for (int i = 1; i <= n; i++) { read(color[i]); belong[i] = i / sz; } for (int i = 1; i <= m; i++) { read(q[i].l), read(q[i].r); q[i].id = i; } sort(q + 1, q + m + 1); int l = 0, r = 0; num[0] = n; for (int i = 1; i <= m; i++) { while (l > q[i].l) Add(color[--l]); while (r < q[i].r) Add(color[++r]); while (l < q[i].l) Sub(color[l++]); while (r > q[i].r) Sub(color[r--]); ans[q[i].id] = max(1, 2 * tot - (q[i].r - q[i].l + 1)); } for (int i = 1; i <= m; i++) printf("%d\n", ans[i]); return0; }