LL solve(int l, int r){ LL res = 0; for (int i = l; i <= r; ++i) cnt2[a[i]] = 0; for (int i = l; i <= r; ++i) { cnt2[a[i]]++; res = max(res, 1LL * cnt2[a[i]] * old[a[i]]); } return res; }
其余情况下根据前面所说,可以实现
1 2 3 4 5 6
while (r < q[i].r) add(++r); // 右指针右移,添加贡献 LL tmp = Ans; // 记录左指针移动前的答案 while (l > q[i].l) add(--l); // 左指针左移,添加贡献 ans[q[i].id] = Ans; while (l < rpos[k] + 1) cnt[a[l++]]--; // 左指针移动回右边界,并途中删除对cnt的贡献 Ans = tmp; // 回滚到移动前的答案
inlineintread(){ int x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();} while (isdigit(ch)) {x = x * 10 + ch - 48; ch = getchar();} return x * f; }
constint maxn = 100010;
int n, m, len, l, r; int a[maxn], cnt[maxn], rpos[maxn], old[maxn], cnt2[maxn]; LL Ans, ans[maxn];
structQuery { int l, r, id, pos; }q[maxn]; boolcmp(Query a, Query b){ if (a.pos != b.pos) return a.pos < b.pos; return a.r < b.r; }
LL solve(int l, int r){ LL res = 0; for (int i = l; i <= r; ++i) cnt2[a[i]] = 0; for (int i = l; i <= r; ++i) { cnt2[a[i]]++; res = max(res, 1LL * cnt2[a[i]] * old[a[i]]); } return res; }