int lenpart, inpart[MAXn + 10]; voidEvaInpart(int n, int m){ lenpart = ceil((double)n / sqrt(ceil((double)m))); for (int i = 1; i <= n; ++i) { inpart[i] = i / lenpart; } }
structQuery { int l, r, id; inlinebooloperator<(const Query sec) const { if (inpart[l] == inpart[sec.l]) { return inpart[l] & 1 ? r < sec.r : sec.r < r; } return l < sec.l; } } que[MAXm + 10];
int n, m, a[MAXn + 10]; int sum, buc[MAXc + 10], ans[MAXm + 10]; inlinevoidadd(int v){/* ... */} inlinevoiddel(int v){/* ... */} voidMocap(){ for (int i = 1, l = 1, r = 0; i <= m; ++i) { while (l > que[i].l) add(a[--l]); while (r < que[i].r) add(a[++r]); while (l < que[i].l) del(a[l++]); while (r > que[i].r) del(a[r--]); // 记录答案 } }
int lenpart, inpart[MAXn + 10]; voidEvaInpart(int n, int m){ lenpart = ceil((double)n / sqrt((double)m)); for (int i = 1; i <= n; ++i) { inpart[i] = i / lenpart; } }
int n, m, a[MAXn + 10]; int cntmap, mapup[MAXn + 10]; map<int, int> mapdown; structQuery { int l, r, idx; inlinebooloperator<(const Query sec) const { if (inpart[l] == inpart[sec.l]) { return r < sec.r; } return l < sec.l; } } que[MAXm + 10];
int buc[MAXn + 10], res, ans[MAXm + 10]; inlinevoidadd(int v){/* ... */} voidMocap(){ for (int i = 1, j = 1; i <= m; i = j) { while (j <= m && inpart[que[i].l] == inpart[que[j].l]) ++j; int k = i; for (; k < j; ++k) { if (inpart[que[k].l] == inpart[que[k].r]) { for (int p = que[k].l; p <= que[k].r; ++p) add(a[p]); ans[que[k].idx] = res; for (int p = que[k].l; p <= que[k].r; ++p) --buc[a[p]]; res = 0; } elsebreak; } for (int r = inpart[que[i].l] * lenpart + lenpart - 1; k < j; ++k) { if (inpart[que[k].l] != inpart[que[k].r]) { while (r < que[k].r) add(a[++r]); int backup = res; for (int l = inpart[que[i].l] * lenpart + lenpart - 1; l >= que[k].l; --l) add(a[l]); ans[que[k].idx] = res; for (int l = inpart[que[i].l] * lenpart + lenpart - 1; l >= que[k].l; --l) --buc[a[l]]; res = backup; } } memset(buc, 0, sizeof(buc)); res = 0; } }