typedefstruct{ int order; int block; int ans; int l; int r; }p;
boolcmp_l(p a, p b) { return a.l < b.l; }
boolcmp_block(p a, p b) { if (a.block == b.block) return a.r < b.r; elsereturn a.block < b.block; } // 奇偶分块的cmp,只需将line66的cmp函数替换成这个就可以了 boolcmp_block_odd_even(p a, p b) { if (a.block == b.block) { if (a.block % 2)return a.r < b.r; elsereturn a.r > b.r; } elsereturn a.block < b.block; }
boolcmp_order(p a, p b) { return a.order < b.order; }
intmain() { int a[mmax]; int cnt[mmax]; p inq[mmax]; for (int i = 0; i < mmax; i++) cnt[i] = 0; int n, m, k; cin >> n >> m >> k; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; inq[i].l = a; inq[i].r = b; inq[i].order = i; } int block_lenth = n / int(sqrt(m * 2 / 3)); for (int i = 0; i < m; i++) { inq[i].block = inq[i].l / block_lenth; } sort(inq, inq + m, cmp_block); int ans = 0; for (int i = inq[0].l - 1; i < inq[0].r; i++) { cnt[a[i]]++; ans += 2 * cnt[a[i]] - 1; } inq[0].ans = ans; int lp = inq[0].l; int rp = inq[0].r;